要操作Outlook郵件,可以使用Microsoft.Office.Interop.Outlook命名空間提供的類和方法。以下是一些常見的操作:
using Outlook = Microsoft.Office.Interop.Outlook;
Outlook.Application outlookApp = new Outlook.Application();
Outlook.MailItem mail = (Outlook.MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
mail.Subject = "Test Email";
mail.Body = "This is a test email.";
mail.To = "receiver@example.com";
mail.Send();
Outlook.Folder inbox = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder;
foreach (Outlook.MailItem mailItem in inbox.Items)
{
Console.WriteLine("Subject: " + mailItem.Subject);
Console.WriteLine("Received Time: " + mailItem.ReceivedTime);
}
Outlook.MailItem replyMail = mail.Reply();
replyMail.Body = "This is a reply email.";
replyMail.Send();
請注意,使用Interop Outlook API需要安裝Outlook應用程序,并且在項目中引用Microsoft.Office.Interop.Outlook程序集。操作Outlook郵件時,也需要考慮到安全性和權限問題,確保有足夠的權限來執行所需的操作。