2
votes

I am trying to use the camel-mail component to send emails from my application using Amazon Simple Email Service. The reason that I am trying to use the camel-mail component not the camel-ses component is that camel-ses does not support attachments.

I am using this to uri:

smtp://$smtpHost:$smtpPort?username=$smtpUsername&password=$smtpPassword&mail.smtp.ssl.enable=true&mail.smtp.ssl.required=true&mail.smtp.auth=true

But I get the error at run-time:

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)

So it appears that Amazon are quite strict about what headers can be sent and Camels approach doesn't play nicely with SES:

Camel copies all of the exchange's IN headers to the MimeMessage headers.

Digging in to the Source, I can see that the class org.apache.camel.component.mail.MailBinding has constructor which accepts a HeaderFilterStrategy:

public MailBinding(HeaderFilterStrategy headerFilterStrategy, ContentTypeResolver contentTypeResolver) {
        this.headerFilterStrategy = headerFilterStrategy;
        this.contentTypeResolver = contentTypeResolver;
}

How can I configure camel-mail to use a custom HeaderFilterStrategy?

1

1 Answers

4
votes

You can configure on the endpoint to use a custom header filter strategy. http://camel.apache.org/how-to-avoid-sending-some-or-all-message-headers.html

You can refer to a custom strategy using the # lookup: http://camel.apache.org/how-do-i-configure-endpoints.html

Then you can use an endpoint uri like

smtp://$smtpHost:$smtpPort?username=$smtpUsername&password=$smtpPassword&mail.smtp.ssl.enable=true&mail.smtp.ssl.required=true&mail.smtp.auth=true&headerFilterStrategy=#myCustomerFilter

Where myCustomFilter is the bean id of the custom filter which you have enlisted in the registry or defined in a Spring XML file (if you use spring), eg < bean id="myCustomFiler" >