الحصول على قائمة الرسائل من مجلد الوارد في صندوق بريد خادم Microsoft Exchange باستخدام Aspose.Email
Contents
[
Hide
]
لاستخدام كائنات أتمتة Office لـ Microsoft Outlook، أضف مراجع إلى مكتبة Microsoft Office ومكتبة Microsoft Office Interop لـ Outlook إلى المشروع. يجب أيضًا تثبيت Microsoft Office Outlook على الجهاز الذي يُشغل فيه الكود.
VSTO
// Create Application class and get namespace
Outlook.Application outlook = new Outlook.Application();
Outlook.NameSpace ns = outlook.GetNamespace("Mapi");
object _missing = Type.Missing;
ns.Logon(_missing, _missing, false, true);
// Get Inbox information in objec of type MAPIFolder
Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
// Unread emails
int unread = inbox.UnReadItemCount;
// Display the subject of emails in the Inbox folder
foreach (Outlook.MailItem mail in inbox.Items)
{
Console.WriteLine(mail.Subject);
}
Aspose.Email
مع ذلك، لا يلزم تثبيت Microsoft Outlook على الجهاز الذي يُشغَّل عليه الكود. أشر إلى Aspose.Email.dll لبناء وتشغيل المشروع بنجاح.
// Create instance of ExchangeClient class by giving credentials
ExchangeClient client = new ExchangeClient("http://MachineName/exchange/Username",
"username", "password", "domain");
// Call ListMessages method to list messages info from Inbox
ExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri);
// Loop through the collection to display the basic information
foreach (ExchangeMessageInfo msgInfo in msgCollection)
{
Console.WriteLine("Subject: " + msgInfo.Subject);
Console.WriteLine("From: " + msgInfo.From.ToString());
Console.WriteLine("To: " + msgInfo.To.ToString());
Console.WriteLine("Message ID: " + msgInfo.MessageId);
Console.WriteLine("Unique URI: " + msgInfo.UniqueUri);
Console.WriteLine("==================================");
}