我是一名新手开发人员,我已经被 EWS 困住了好几个小时。我需要阅读最新的电子邮件,获取所有未读的电子邮件并使用其中的数据来做一些事情。
此时我的代码看起来像这样。
static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new WebCredentials("support@mycompany.com", "mysupersuperdupersecretpassword");
service.AutodiscoverUrl("support@mycompany.com", RedirectionUrlValidationCallback);
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox,new ItemView(2));
foreach (Item item in findResults.Items)
{
// works perfectly until here
Console.WriteLine(item.Subject);
Console.WriteLine('\n');
item.Load();
string temp = item.Body.Text;
// I can't seem to get TextBody to work. so I used a RegEx Match match = Regex.Match(temp, "<body>.*?</body>", RegexOptions.Singleline);
string result = match.Value;
result = result.Replace("<body>", "");
result = result.Replace("</body>", "");
Console.Write(result);
Console.WriteLine('\n');
//Now the email boddy is fine but IsNew always returns false.
if (item.IsNew)
{
Console.WriteLine("This message is unread!");
}
else
{
Console.WriteLine("This message is read!");
}
}
}
我已经用谷歌搜索并尝试并搜索了更多信息,但我被卡住了。我现在如何阅读哪些电子邮件,有没有办法获得比我所做的更有效的电子邮件正文?任何帮助将不胜感激。