英文:
Issues Picking Forwarded Mail from Inbox using Microsoft Exchange in Java
问题
I have a working code that connects to Microsoft Outlook and fetches mail based on some filters. It is working fine with reading the direct mail but not able to pick the same mail if forwarded. Any help is appreciated.
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);
英文:
I have a working code that connects to Microsoft outlook and fetches Mail based on some filters.
It is working fine with reading the direct mail but not able to pick the same mail if forwarded.
Any Help is appreciated.
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);
答案1
得分: 1
以下是翻译好的代码部分:
private static void readAttachmentEmail(ExchangeService service) throws Exception {
// 绑定到收件箱。
Folder inbox = Folder.bind(service, WellKnownFolderName.Inbox);
ItemView view = new ItemView(5);
List<SearchFilter> searchFilterCollection = new ArrayList<>();
// 标志以仅选择带有附件的电子邮件
searchFilterCollection.add(new SearchFilter.IsEqualTo(ItemSchema.HasAttachments, Boolean.TRUE));
// 对于每个渠道
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();
}
});
}
英文:
You must revisit filters in your code.
Here is my code to read attached emails and I am able to print forwarded emails with attachments.
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();
}
});
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论