c#でコード化されたOutlookアドインを使用してOutlookからIMAP /MicrosoftExchange設定を読み取る方法を探しています。
私を助けてくれてありがとう。
c#でコード化されたOutlookアドインを使用してOutlookからIMAP /MicrosoftExchange設定を読み取る方法を探しています。
私を助けてくれてありがとう。
あなたが探しているのは、 dllのAccountsインターフェイスだと思います。Office.Interop.Outlook
使用している Outlook のバージョンについて言及していません。このコードは Outlook 2010 用であり、Microsoft 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 プロパティへのアクセスが含まれていないため、少し異なる操作を行う必要があります。
それを行うには、たとえば償還などのサードパーティのライブラリを使用する必要があります。いくつかの代替案については、この回答を参照してください。
この別の質問への回答に従って、レジストリを使用してそれを行うこともできるようです。