请给我一段C#代码,需求是使用exchange接收163邮箱的邮件
时间: 2024-02-12 08:09:28 浏览: 104
以下是使用 Microsoft Exchange Server Web Services (EWS) 来收取 163 邮箱的邮件的 C# 代码示例:
```
using Microsoft.Exchange.WebServices.Data;
using System;
using System.Net;
namespace ReceiveEmail
{
class Program
{
static void Main(string[] args)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.Credentials = new WebCredentials("YourEmailAddress@163.com", "YourPassword");
service.AutodiscoverUrl("YourEmailAddress@163.com");
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
foreach (Item item in findResults.Items)
{
Console.WriteLine(item.Subject);
Console.WriteLine(item.DateTimeReceived);
Console.WriteLine(item.Body.Text);
}
Console.ReadLine();
}
}
}
```
请注意,您需要将 "YourEmailAddress@163.com" 和 "YourPassword" 替换为您自己的 163 邮箱地址和密码。另外,您需要安装 Microsoft Exchange Server Web Services Managed API 来运行此代码示例。
阅读全文