Our*_*nas 3 c# soap exchangewebservices exchange-server-2010
我正在尝试阅读特定的电子邮件帐户,以查找包含未读附件的项目,并在主题中包含某些单词.
我有下面的代码,但只能读取我的收件箱,而不是我要检查的收件箱
static void Main(string[] args)
{
ServicePointManager.ServerCertificateValidationCallback=CertificateValidationCallBack;
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);// .Exchange2007_SP1);
service.UseDefaultCredentials = true;
service.AutodiscoverUrl("bbtest@domainname.com"); //, RedirectionUrlValidationCallback); //bbtest@bocuk.local
ItemView view = new ItemView(1);
string querystring = "HasAttachments:true Kind:email";
//From:'Philip Livingstone' Subject:'ATTACHMENT TEST' Kind:email";
// Find the first email message in the Inbox that has attachments.
// This results in a FindItem operation call to EWS.
FindItemsResults<Item> results = service.FindItems(WellKnownFolderName.Inbox, querystring, view);
foreach (EmailMessage email in results)
if (email.IsRead == false) // && email.HasAttachments == true
{
System.Diagnostics.Debug.Write("Found attachemnt on msg with subject: " + email.Subject);
// Request all the attachments on the email message.
//This results in a GetItem operation call to EWS.
email.Load(new PropertySet(EmailMessageSchema.Attachments));
foreach (Attachment attachment in email.Attachments)
{
if (attachment is FileAttachment)
...
Run Code Online (Sandbox Code Playgroud)
我需要更改什么才能让我的代码读取bbtest@domainname.com收件箱中的邮件?
小智 7
默认情况下,在ExchangeService对象上调用FindItems时,您的邮箱'收件箱文件夹将设置为root .假设您的域帐户具有访问其他邮箱所需的权限,则以下操作应该可以解决问题.我已经省略了服务创建部分.
//creates an object that will represent the desired mailbox
Mailbox mb = new Mailbox(@"othermailbox@domain.com");
//creates a folder object that will point to inbox folder
FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);
//this will bind the mailbox you're looking for using your service instance
Folder inbox = Folder.Bind(service, fid);
//load items from mailbox inbox folder
if(inbox != null)
{
FindItemsResults<Item> items = inbox.FindItems(new ItemView(100));
foreach(var item in items)
Console.WriteLine(item);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10998 次 |
最近记录: |