2 Pluspunkte 0 Minuspunkte

Ich habe diesen Code um eine Email mit Outlook zu senden.

using Outlook = Microsoft.Office.Interop.Outlook;

var application = new Application();
var mail = (_MailItem)application.CreateItem(OlItemType.olMailItem);
mail.To = "empfaenger.account@mail.at";
mail.Subject = "Eine Testmail";
mail.Body = "Das ist eine Testmail. Bitte nicht antworten!";
Outlook.Account account = application.Session.Accounts["absender.account@mail.at"];
mail.SendUsingAccount = account;
mail.Send();

Wie kann ich alle Emails aus Outlook mit C# anzeigen?

von  

1 Antwort

1 Pluspunkt 0 Minuspunkte

Hier ist ein Beispielcode um alle Emails von Outlook in C# anzuzeigen.

// Erstellen Sie eine Instanz von Outlook
Outlook.Application outlookApp = new Outlook.Application();

// Holen Sie sich die MAPI-Ordner
Outlook.NameSpace outlookNamespace = outlookApp.GetNamespace("MAPI");
Outlook.MAPIFolder inbox = outlookNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

// Durchlaufen Sie die E-Mails im Posteingang
foreach (object item in inbox.Items)
{
    if (item is Outlook.MailItem)
    {
        Outlook.MailItem mailItem = (Outlook.MailItem)item;

        // Zugriff auf Informationen zur E-Mail
        Console.WriteLine("Betreff: " + mailItem.Subject);
        Console.WriteLine("Von: " + mailItem.SenderEmailAddress);
        Console.WriteLine("Nachrichtentext: " + mailItem.Body);
        Console.WriteLine("-------------------------------------------");
    }
}

// Aufräumen
Marshal.ReleaseComObject(inbox);
Marshal.ReleaseComObject(outlookNamespace);
Marshal.ReleaseComObject(outlookApp);
von (396 Punkte)