c# - 通过 C# 获取 Outlook 邮箱地址

标签 c# outlook

我需要能够使用 C# 代码获取当前登录用户的电子邮件地址。

我需要完整地址,而不仅仅是假定的电子邮件帐户(例如 user@localdomain.com.au),尽管这适用于大多数客户。

任何帮助将不胜感激。

最佳答案

试试这个,来自 http://msdn.microsoft.com/en-us/library/ff462091.aspx :

using System;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;

namespace OutlookAddIn1
{
    class Sample
    {
        public static void DisplayAccountInformation(Outlook.Application application)
        {

            // The Namespace Object (Session) has a collection of accounts.
            Outlook.Accounts accounts = application.Session.Accounts;

            // Concatenate a message with information about all accounts.
            StringBuilder builder = new StringBuilder();

            // Loop over all accounts and print detail account information.
            // All properties of the Account object are read-only.
            foreach (Outlook.Account account in accounts)
            {

                // The DisplayName property represents the friendly name of the account.
                builder.AppendFormat("DisplayName: {0}\n", account.DisplayName);

                // The UserName property provides an account-based context to determine identity.
                builder.AppendFormat("UserName: {0}\n", account.UserName);

                // The SmtpAddress property provides the SMTP address for the account.
                builder.AppendFormat("SmtpAddress: {0}\n", account.SmtpAddress);

                // The AccountType property indicates the type of the account.
                builder.Append("AccountType: ");
                switch (account.AccountType)
                {

                    case Outlook.OlAccountType.olExchange:
                        builder.AppendLine("Exchange");
                        break;

                    case Outlook.OlAccountType.olHttp:
                        builder.AppendLine("Http");
                        break;

                    case Outlook.OlAccountType.olImap:
                        builder.AppendLine("Imap");
                        break;

                    case Outlook.OlAccountType.olOtherAccount:
                        builder.AppendLine("Other");
                        break;

                    case Outlook.OlAccountType.olPop3:
                        builder.AppendLine("Pop3");
                        break;
                }

                builder.AppendLine();
            }

            // Display the account information.
            System.Windows.Forms.MessageBox.Show(builder.ToString());
        }
    }
}

关于c# - 通过 C# 获取 Outlook 邮箱地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18606088/

相关文章:

vba - 如果存在旧的未读邮件,请发送电子邮件

c# - 根据读取输入实例化子类

c# - 在 Azure Function 中处置 NLog

c# - 如何在不失去单元测试能力的情况下将日志记录添加到静态类?

c# - 如何将 nunit 测试结果包含在 sonarcube 4.5.1 c# 插件 3.3 sonar-project.properties 文件中?

C# Outlook 2010 - 使用 'this.Application' 时出错

c# - 当用户单击 Collection View 时如何显示图像

outlook - 时事通讯跟踪图像 Outlook

用于打开 MSG 文件的 C# Outlook 互操作和 OpenSharedItem

azure - 如何获取microsoft graph中所有房间(或选定用户)的所有事件?