【解決方法】Outlookアカウント内のメールボックスにアクセスすると、電子メールIDが見つかりますc#.net Outlook 2013

プログラミングQA


C#
I am writing an application that will automate the sending of E-Mails from a specific mailbox within the account available on Outlook. Currently I am able to get the accounts available by doing:
C#
Outlook.Application application = new Outlook.Application();
Outlook.Accounts accounts = application.Session.Accounts;

C#
I can then iterate through the available accounts by doing:

foreach (Outlook.Account account in accounts)
{
    Console.WriteLine(account.DisplayName);
}

My question is: How do I access the mailboxes within an Exchange Account in the list. Lets say the first element in the accounts list.

I have read a few other questions on accessing the Inbox folder contents of a mailbox, but I am looking to send an email item I later create using the chosen mailbox in the "From" field.

Thanks for any help.

私が試したこと:

Outlook.Application アプリケーション = 新しい Outlook.Application();
Outlook.Accounts アカウント = application.Session.Accounts;

次に、次のようにして、使用可能なアカウントを反復処理できます。

foreach (アカウント内の Outlook.Account アカウント)
{
Console.WriteLine(アカウント.DisplayName);
}

解決策 1

あなたが持っているコードは、ローカルマシンで開発しているためのみ機能しています。サーバーに公開すると、コードは機能しなくなります。 Outlook は、さまざまな理由からサーバー側の自動化に適していないデスクトップ アプリケーションであり、その自動化は Microsoft によってサポートされていません。 メール データにアクセスする場合は、POP3 または IMAP と SMTP を使用して送信します。 アカウントが Exchange に保持されている場合は、Exchange Web サービスを使用してやり取りします。

Outlook を自動化しようとしても問題は解決しません。

解決策 2

各アカウントを使用して個別の情報を取得する方法の例を示すメソッドを作成しました

public static void SaveEmails(Account account)
{
    Microsoft.Office.Interop.Outlook.Application outlookApplication = account.Application;
    NameSpace outlookNamespace = outlookApplication.GetNamespace("MAPI");
    Accounts accounts = outlookNamespace.Accounts;
    MAPIFolder inboxFolder = outlookNamespace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
    Items Items = inboxFolder.Items;
    List<MailItem> mailItems = new List<MailItem>();

    foreach (Object email in Items)
    {
        if (email is MailItem)
        {
            mailItems.Add((MailItem)email);

        }

    }

    foreach (MailItem email in mailItems)
    {
        string name = email.Subject;
        Console.WriteLine(name);


    }
}

コメント

タイトルとURLをコピーしました