Aspose.Email是用于轻松的开发 email 功能的应用程序的一组控件,基于 ASP.NET 的Web应用、Web服务和Windows 应用。允许开发者直接与 SMTP, POP, FTP, 和 MS Exchange 服务器进行工作。支持邮件合并、行事历、定制邮件标题和内容、嵌入文件等。
Microsoft Exchange Server是一个平台,可让您管理联系人,电子邮件,日历,日程安排并提供多种协作功能。使用MS Exchange Server,您可以部署自己的邮件服务器,而无需依赖第三方。也可以通过Web服务从您的Web,桌面或移动应用程序中访问MS Exchange Server。
- 连接到MS Exchange Server
- 使用EWS从Exchange Server读取电子邮件
- 使用IMAP从Exchange Server读取电子邮件
17一齐周年庆!整合所有格式的Aspose.Total永久授权正在火热促销中,乐享85折起!联系客服立马1分钟了解全部咨询!
使用C#连接到Exchange Server
用于.NET的Aspose.Email提供了两种连接到Exchange Server实例的方法:EWS和IMAP。以下各节提供了使用任何一种方法建立连接的步骤。
通过EWS连接到Exchange Server
以下是使用Aspose.Email for .NET连接到MS Exchange Server的步骤。
- 使用NetworkCredential类设置凭据,包括用户名,密码和域。
- 获取由EWSClient.GetEWSClient(String,ICredentials)方法返回的IEWSClient对象。
- 使用IEWSClient对象执行进一步的操作。
下面的代码示例演示如何使用C#通过EWS连接到Exchange Server。
private static IEWSClient GetExchangeEWSClient(){ const string mailboxUri = "https://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。
- 创建ImapClient类的实例,并向其构造函数提供主机,用户名和密码。
- 使用ImapClient.SecurityOptions属性设置安全选项。
- 使用ImapClient对象访问邮箱中的项目。
下面的代码示例演示如何使用C#通过IMAP访问Exchange Server。
ImapClient imapClient = new ImapClient("ex07sp1", "Administrator", "Evaluation1");imapClient.SecurityOptions = SecurityOptions.Auto;
在C#中使用EWS从Exchange Server读取电子邮件
以下是使用EWS从Exchange Server读取电子邮件的步骤。
- 创建IEWSClient的实例 。
- 使用IEWSClient.ListMessage(String)方法访问电子邮件集合。
- 循环浏览电子邮件集合,以获取每封电子邮件的详细信息。
下面的代码示例演示如何使用C#从Exchange Server中读取电子邮件。
// Create instance of ExchangeWebServiceClient class by giving credentialsIEWSClient client = EWSClient.GetEWSClient("https://outlook.office365.com/ews/exchange.asmx", "UserName", "Password");// Call ListMessages method to list messages info from InboxExchangeMessageInfoCollection msgCollection = client.ListMessages(client.MailboxInfo.InboxUri);// Loop through the collection to display the basic informationforeach (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读取电子邮件的步骤。
- 创建ImapClient类的实例,并向其构造函数提供主机,用户名和密码。
- 使用ImapClient.SecurityOptions属性设置安全选项。
- 使用ImapClient.SelectFolder()方法选择一个文件夹,例如收件箱,已发送文件夹等。
- 使用ImapClient.ListMessages()方法获取电子邮件集合。
- 循环浏览电子邮件集合以访问每个消息。
下面的代码示例演示如何使用IMAP从Exchange Server中读取电子邮件。
// Connect to Exchange Server using ImapClient classImapClient imapClient = new ImapClient("ex07sp1", "Administrator", "Evaluation1");imapClient.SecurityOptions = SecurityOptions.Auto;// Select the Inbox folderimapClient.SelectFolder(ImapFolderInfo.InBox);// Get the list of messagesImapMessageInfoCollection msgCollection = imapClient.ListMessages();foreach (ImapMessageInfo msgInfo in msgCollection){ Console.WriteLine(msgInfo.Subject);}// Disconnect from the serverimapClient.Dispose();
还想要更多吗可以点击阅读【2020 · Aspose最新资源整合】,查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询。
标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!