翻譯|使用教程|編輯:李顯亮|2020-11-24 09:47:32.527|閱讀 621 次
概述:Microsoft Exchange Server是一個平臺,可讓您管理聯(lián)系人,電子郵件,日歷,日程安排并提供多種協(xié)作功能。在本文中,將學習如何連接到Exchange Server以及如何使用C#閱讀電子郵件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Email是用于輕松的開發(fā) email 功能的應用程序的一組控件,基于 ASP.NET 的Web應用、Web服務和Windows 應用。允許開發(fā)者直接與 SMTP, POP, FTP, 和 MS Exchange 服務器進行工作。支持郵件合并、行事歷、定制郵件標題和內容、嵌入文件等。
Microsoft Exchange Server是一個平臺,可讓您管理聯(lián)系人,電子郵件,日歷,日程安排并提供多種協(xié)作功能。使用MS Exchange Server,您可以部署自己的郵件服務器,而無需依賴第三方。也可以通過Web服務從您的Web,桌面或移動應用程序中訪問MS Exchange Server。
在本文中,將學習如何連接到Exchange Server以及如何使用C#閱讀電子郵件。
慧都17一齊周年慶!整合所有格式的Aspose.Total永久授權正在火熱促銷中,樂享85折起!立馬1分鐘了解全部咨詢!
用于.NET的Aspose.Email提供了兩種連接到Exchange Server實例的方法:EWS和IMAP。以下各節(jié)提供了使用任何一種方法建立連接的步驟。
通過EWS連接到Exchange Server
以下是使用Aspose.Email for .NET連接到MS Exchange Server的步驟。
下面的代碼示例演示如何使用C#通過EWS連接到Exchange Server。
private static IEWSClient GetExchangeEWSClient() { const string mailboxUri = "http://outlook.office365.com/ews/exchange.asmx"; const string domain = @""; const string username = @"username@ASE305.onmicrosoft.com"; const string password = @"password"; NetworkCredential credentials = new NetworkCredential(username, password, domain); IEWSClient client = EWSClient.GetEWSClient(mailboxUri, credentials); return client; }
通過IMAP連接到Exchange Server
為了通過IMAP連接到Exchange Server,請確保在服務器上啟用了IMAP服務。完成后,請按照以下步驟連接到Exchange Server。
下面的代碼示例演示如何使用C#通過IMAP訪問Exchange Server。
ImapClient imapClient = new ImapClient("ex07sp1", "Administrator", "Evaluation1"); imapClient.SecurityOptions = SecurityOptions.Auto;
以下是使用EWS從Exchange Server讀取電子郵件的步驟。
下面的代碼示例演示如何使用C#從Exchange Server中讀取電子郵件。
// Create instance of ExchangeWebServiceClient class by giving credentials IEWSClient client = EWSClient.GetEWSClient("http://outlook.office365.com/ews/exchange.asmx", "UserName", "Password"); // 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); }
以下是使用IMAP從Exchange Server讀取電子郵件的步驟。
下面的代碼示例演示如何使用IMAP從Exchange Server中讀取電子郵件。
// Connect to Exchange Server using ImapClient class ImapClient imapClient = new ImapClient("ex07sp1", "Administrator", "Evaluation1"); imapClient.SecurityOptions = SecurityOptions.Auto; // Select the Inbox folder imapClient.SelectFolder(ImapFolderInfo.InBox); // Get the list of messages ImapMessageInfoCollection msgCollection = imapClient.ListMessages(); foreach (ImapMessageInfo msgInfo in msgCollection) { Console.WriteLine(msgInfo.Subject); } // Disconnect from the server imapClient.Dispose();
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn