繁体   English   中英

Spring集成入站电子邮件适配器

[英]Spring integration inbound email adapter

我可以使用IMAP入站适配器中的mail-filter-expression属性基于发件人电子邮件ID拒绝电子邮件吗

如果您表示“拒绝”,则表示只是从AbstractMailReceiver忽略,然后是...

if (this.selectorExpression.getValue(this.evaluationContext, message, Boolean.class)) {
    filteredMessages.add(message);
}
else {
    if (logger.isDebugEnabled()){
        logger.debug("Fetched email with subject '" + message.getSubject() + "' will be discarded by the matching filter" +
                        " and will not be flagged as SEEN.");
    }
}

编辑:

表达式的#root对象是MimeMessage getFrom()返回一个Address[] ,例如

"from == null || from.length == 0 ? false : from[0].toString().contains('something.org') ? true : false" 

应该管用。

对于更复杂的事情,您可以编写Java类,将其定义为Bean,然后从表达式"@myMailFilter.filter(#root)"

编辑2:

请注意,如果使用IMAP,您还可以使用search-term-strategy来限制甚至被考虑(检索)的电子邮件。

例如:

@Override
public SearchTerm generateSearchTerm(Flags supportedFlags, Folder folder) {
    try {
        return new FromTerm(new InternetAddress("*@something.org"));
    }
    catch (AddressException e) {
        throw new RuntimeException(e);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM