【问题标题】:Issues Picking Forwarded Mail from Inbox using Microsoft Exchange in Java使用 Java 中的 Microsoft Exchange 从收件箱中提取转发邮件的问题
【发布时间】:2020-04-10 14:40:52
【问题描述】:

我有一个连接到 Microsoft Outlook 并根据某些过滤器获取邮件的工作代码。 阅读直接邮件可以正常工作,但如果转发则无法选择相同的邮件。 任何帮助表示赞赏。

    List<SearchFilter> searchFilterCollection = new ArrayList<>();
    searchFilterCollection.add(new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived,localDate));

    // flag to pick only email which contains attachments
    searchFilterCollection.add(new SearchFilter.IsEqualTo(ItemSchema.HasAttachments, Boolean.TRUE));
    List<MetaInfoDTO> filterList = channel.getFilters();
    // for each channel
    log.info("Email from: {}", definedChannelFilter.getFieldData());
    EmailAddress manager = new EmailAddress("abcd@outlook.com");
    SearchFilter.IsEqualTo fromManagerFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.Sender, manager);
    searchFilterCollection.add(fromManagerFilter);
    log.info("Email Subject: {}", definedChannelFilter.getFieldData());
    searchFilterCollection.add(new SearchFilter.ContainsSubstring(ItemSchema.Subject,"Subject ASDF"));
    log.info("Email Body Content: {}", definedChannelFilter.getFieldData());
    searchFilterCollection.add(new SearchFilter.ContainsSubstring(ItemSchema.Body,"Body Content if any"));

    return new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchFilterCollection);        

【问题讨论】:

  • 我相信你正在使用 ews-java-api 阅读,你能提到 ews-java-api 的版本并将代码编辑到mwe

标签: java outlook.com


【解决方案1】:

您必须重新访问代码中的过滤器。

这是我阅读附件电子邮件的代码,我可以打印带有附件的转发电子邮件。

private static void readAttachmentEmail(ExchangeService service) throws Exception {
        // Bind to the Inbox.
        Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);
        ItemView view = new ItemView(5);
        List<SearchFilter> searchFilterCollection = new ArrayList<>();
        // flag to pick only email which contains attachments
        searchFilterCollection.add(new SearchFilter.IsEqualTo(ItemSchema.HasAttachments, Boolean.TRUE));
        // for each channel
        EmailAddress manager = new EmailAddress("manager@email.com");
        SearchFilter.IsEqualTo fromManagerFilter = new SearchFilter.IsEqualTo(EmailMessageSchema.Sender, manager);
        searchFilterCollection.add(fromManagerFilter);
        //searchFilterCollection.add(new SearchFilter.ContainsSubstring(ItemSchema.Subject,"Subject ASDF"));
        //searchFilterCollection.add(new SearchFilter.ContainsSubstring(ItemSchema.Body,"Body Content if any"));
        SearchFilter finalSearchFilter = new SearchFilter.SearchFilterCollection(LogicalOperator.And, searchFilterCollection);
        service.findItems(inbox.getId(), finalSearchFilter, view).forEach(item->{
            try {
                System.out.println("id==========" + item.getId());
                System.out.println("sub==========" + item.getSubject());
            } catch (ServiceLocalException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        });
    }

【讨论】:

    猜你喜欢
    • 2011-03-04
    • 2014-05-19
    • 2015-08-10
    • 2013-12-02
    • 1970-01-01
    • 1970-01-01
    • 2014-08-15
    • 2013-04-25
    • 1970-01-01
    相关资源
    最近更新 更多