簡體   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