我正在尝试使用camel-mail组件使用Amazon Simple Email Service从我的应用程序发送电子邮件。我试图使用camel-mail组件而不是camel-ses组件的原因是camel-ses不支持附件。
我正在使用它来uri:
smtp://$smtpHost:$smtpPort?username=$smtpUsername&password=$smtpPassword&mail.smtp.ssl.enable=true&mail.smtp.ssl.required=true&mail.smtp.auth=true
但我在运行时遇到错误:
com.sun.mail.smtp.SMTPSendFailedException: 554 Transaction failed: Illegal header 'breadcrumbId'.
at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:2114)
at com.sun.mail.smtp.SMTPTransport.finishData(SMTPTransport.java:1900)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1122)
at org.apache.camel.component.mail.DefaultJavaMailSender.send(DefaultJavaMailSender.java:124)
at org.apache.camel.component.mail.MailProducer.process(MailProducer.java:49)
所以看来亚马逊对于可以发送什么标题非常严格,而且Camels方法与SES的搭配不是很好:
Camel将所有交换的IN标头复制到MimeMessage 头。
深入了解Source,我可以看到类org.apache.camel.component.mail.MailBinding
具有接受HeaderFilterStrategy
的构造函数:
public MailBinding(HeaderFilterStrategy headerFilterStrategy, ContentTypeResolver contentTypeResolver) {
this.headerFilterStrategy = headerFilterStrategy;
this.contentTypeResolver = contentTypeResolver;
}
如何配置camel-mail以使用自定义HeaderFilterStrategy
?
答案 0 :(得分:4)
您可以在端点上配置使用自定义标头过滤器策略。 http://camel.apache.org/how-to-avoid-sending-some-or-all-message-headers.html
您可以使用#lookup:http://camel.apache.org/how-do-i-configure-endpoints.html
来引用自定义策略然后你可以使用像
这样的端点smtp://$smtpHost:$smtpPort?username=$smtpUsername&password=$smtpPassword&mail.smtp.ssl.enable=true&mail.smtp.ssl.required=true&mail.smtp.auth=true&headerFilterStrategy=#myCustomerFilter
其中myCustomFilter是您在注册表中登记或在Spring XML文件中定义的自定义过滤器的bean id(如果使用spring),例如< bean id =“myCustomFiler”>