3
我是一名新手開發人員,現在我一直堅持使用EWS幾個小時。我需要閱讀最近的電子郵件,獲取所有未讀電子郵件,並使用他們的數據做一些事情。EWS託管API。 IsNew總是返回false並且不能使用TextBody
在這一刻我的代碼看起來像這樣。
static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback = CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
service.Credentials = new WebCredentials("[email protected]", "mysupersuperdupersecretpassword");
service.AutodiscoverUrl("[email protected]", 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!");
}
}
}
我用Google搜索,並試圖和google搜索多一些,我卡住了。我現在如何閱讀哪些電子郵件,是否有辦法讓電子郵件正文文本比我所做的更有效?任何幫助將超級讚賞。
其實我讀與此相似的文章。我將發佈一個答案,展示我現在擁有的東西。這是更接近!謝謝您的回覆。 – KapteinMarshall
編輯你的問題,不要發佈答案,除非它解決了。 – James
ooooops ....我有點新的堆棧溢出...我會記住,下次 – KapteinMarshall