繁体   English   中英

Outlook加载项读取服务器设置

[英]Outlook Add-in read Server Settings

我正在寻找一种使用c#编码的Outlook加载项从Outlook读出IMAP / Microsoft Exchange设置的方法。

谢谢你帮我

我认为您正在寻找的是Office.Interop.Outlook dll的Accounts接口。

您没有提到您使用的是哪个版本的Outlook,此代码适用于由Microsoft MVP Helmut Obertanner编写的Outlook 2010,摘自此处

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属性的访问。

为此,您要么必须使用第三方库(例如,兑换),否则请参见此答案

您显然也可以根据另一个问题的答案使用注册表。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM