我们刚刚切换到Microsoft Exchange Online(EOP和EOP2),电子邮件工作正常。
现在,我只想打开一个邮箱,扫描所有电子邮件并返回简单信息,例如Sender
或MailDate
等
我需要的只是一个简单的工作示例。我得到的最接近的是下面的
FindItemsResults<Item> items = await serviceInstance.FindItems(WellKnownFolderName.Inbox, "to:" + sEmail, new ItemView(15));
但这给了我这个错误
Cannot implicitly convert type 'System.Threading.Tasks.Task<Microsoft.Exchange.WebServices.Data.FindItemsResults<Microsoft.Exchange.WebServices.Data.Item>>' to 'Microsoft.Exchange.WebServices.Data.FindItemsResults<Microsoft.Exchange.WebServices.Data.Item>'
string sEmail = "xxxxxx@xxxxxxx.co,";
string sPassword = "*********";
string sResult = "";
ExchangeService serviceInstance = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
//Provide the account user credentials
serviceInstance.Credentials = new WebCredentials(sEmail, sPassword);//ConfigurationManager.AppSettings["Domain"].ToString());
try
{
// Use Autodiscover to set the URL endpoint.
serviceInstance.AutodiscoverUrl(sEmail, RedirectionUrlValidationCallback); //works up to here
//error here
FindItemsResults<Item> items = serviceInstance.FindItems(WellKnownFolderName.Inbox, "to:" + sEmail, new ItemView(15));
//no error here but can't do a foreach on "items"
//var items = serviceInstance.FindItems(WellKnownFolderName.Inbox, "to:" + sEmail, new ItemView(15));
sResult = "Found:" + "\r\n";
foreach (EmailMessage msg in items)
{
sResult += msg.Subject + "\r\n";
}
}
catch (Exception ex)
{
serviceInstance = null;
sResult = ex.Message;
}
我做错了什么,以前很简单?
我正在使用
在这里和其他站点,我尝试了无数示例。
请问有人有一个非常简单的工作示例吗
答案 0 :(得分:0)
杰克
我测试您的代码,在serviceInstance.FindItems方法中获得以下错误。
参数queryString仅对Exchange Server版本Exchange2010或更高版本有效。
因此,您应该创建一个Exchange 2010或更高版本的Exchange Server。 下面是详细的代码。
Xcode
最好的问候,
埃文
答案 1 :(得分:0)
尝试以下操作:
var items = serviceInstance.FindItems(WellKnownFolderName.Inbox, "to:" + sEmail, new ItemView(15));
var emailMessages = items.Items.Cast<EmailMessage>();
或
var emailMessages = items.Items.OfType<EmailMessage>();
然后您的foreach
应该可以工作。