Mule SMTP - send email with attachment

2020-04-19 10:07发布

问题:

I am trying to use Mule 3.3.0 and configure an SMTP Endpoint. The flow can have a File Inbound Endpoint and a SMTP outbound endpoint. Another flow can have a Java class that generates a String content (body of the email) and also creates a CSV file that it will try to push to the SMTP Outbound Endpoint.

Unforutnately it doesn't seem Mule SMTP supports attachment out of the box by simple configuration. I read up in the web and seems one way to do it is write your own transformer. TO be able to send an attachment with an email is quite a basic feature and I am looking forward to hear answers from Mule experts if this is possible by simple configs.

回答1:

It can be done in two ways.

One with Mule configuration

<set-attachment attachmentName="" value="" contentType="" />

Second with Mule API.

org.mule.api.MuleMessage.addOutboundAttachment(String arg0, Object arg1, String arg2) 

or

org.mule.api.MuleMessage.addOutboundAttachment(String arg0, DataHandler arg1)

Hope this helps.



回答2:

To send attachments, add them to the Mule Message outbound attachments.

See addOutboundAttachment in http://www.mulesoft.org/docs/site/3.3.0/apidocs/index.html?org/mule/api/MuleMessage.html