Outlook加载项读取服务器设置

本文关键字:设置 服务器 读取 加载项 Outlook | 更新日期: 2023-09-27 17:53:46

我正在寻找一种方法从Outlook中读取IMAP/Microsoft Exchange设置,使用c#编写的Outlook插件。

谢谢你的帮助

Outlook加载项读取服务器设置

我想你要找的是Office.Interop.Outlook dll的Accounts接口。

你没有提到你使用的是哪个版本的Outlook,这是Outlook 2010的代码,由微软MVP Helmut Obertanner编写,摘自这里:

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());
        }
    }
}

我可以从文档中看到,这在理论上应该也适用于Outlook 2007。

如果你打算使用Outlook 2003,你将不得不做一些不同的事情,因为Outlook 2003对象模型不包括对Accounts属性的访问。

要做到这一点,您要么必须使用第三方库,如redemption,例如,请参阅此答案以获得一些替代方案。

显然,你也可以使用注册表来做到这一点,根据这个问题的答案。

对于交换设置,您可以检查此选项http://msdn.microsoft.com/en-US/exchange