【问题标题】:EWS only reading my inbox [duplicate]EWS 只阅读我的收件箱 [重复]
【发布时间】:2014-04-15 00:09:01
【问题描述】:

我正在尝试阅读特定的电子邮件帐户,以查找带有未读附件且主题中有特定字词的项目。

我有以下代码有效,但只读取我的收件箱不是我要检查的收件箱

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)
...

我需要进行哪些更改才能让我的代码读取 bbtest@domainname.com 收件箱中的消息?

【问题讨论】:

  • @JakobChristensen : - 我认为你是对的......我现在遇到了一个错误问题 在商店中找不到指定的对象。
  • 哪行代码给你这个错误?
  • @JakobChristensen:这会受到我的测试电子邮件帐户被隐藏的影响吗?
  • 也许吧。您是否在自动发现期间或调用 FindItems 时收到错误?
  • 它是在 FindItems 期间,但我已将其取消隐藏,我将使用网络凭据来确保我可以读取目标邮箱。

标签: c# soap exchangewebservices exchange-server-2010


【解决方案1】:

默认情况下,当在 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);
}

【讨论】:

  • +1 非常感谢,但我现在收到错误消息“在商店中找不到指定的对象。” - 有什么想法吗?
  • 你从哪里得到这个错误?确保您使用的帐户具有访问目标邮箱所需的所有权限。我的公司有一个类似的设置,相信我的代码就像一个魅力。
  • 我的测试邮箱账户被隐藏会不会影响这个问题?
  • 可能是的,我不确定,但您可能仍然可以连接到隐藏邮箱。您必须向系统管理员询问该邮箱的 Distinguished Name 并在 Mailbox 构造函数中使用 if 而不是电子邮件地址。或者只是取消隐藏邮箱。
猜你喜欢
  • 2011-11-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多