Sending formatted mails with Mule

本秂侑毒 提交于 2020-01-11 06:47:09

问题


I'm sending emails using Mule. I need to add format to the text I send. The content of the mail is the payload which has a String in it that I form in a Java method and send to the flow with an Expression transformer. I need to add format to that String: bold, underline, colour.... How can I do it?

This is an extract of my flow:

   <expression-transformer expression="#[com.generateText4Email(payload)]" doc:name="mailText"/>
<smtp:outbound-endpoint host="${smtp.host}"
        responseTimeout="10000" doc:name="SMTP" connector-ref="smtpConnector"
        from="${smtp.from}" port="${smtp.port}" subject="Invoice"
        to="mail@mail.com" />

I've tried with this but it doesn't work.

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"><head><title>Email</title></head><body style="font-family:'Century Gothic'"><h1 style="text-align:center;"> company </h1><h2 style="font-size:14px;">Name : name <br />Company : arch <br />Email : qqq@aaaa.com</h2><p>fin</p></body></html>

Thanks in advance.


回答1:


I solved it. I was missing setting content-type in the smtp:connector and the mime-type in the smtp:outbpund-endbound as text/html for the to work. This is the correct code:

<smtp:connector name="smtpConnector"
    validateConnections="true" doc:name="SMTP" contentType="text/html"/>
 <smtp:outbound-endpoint host="${smtp.host}"
    responseTimeout="10000" doc:name="SMTP" connector-ref="smtpConnector"
    from="${smtp.from}" port="${smtp.port}" subject="Invoice"
    to="mail@mail.com"" mimeType="text/html"/>

With this configuration you can use html in your text like this

<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"><head><title>Email</title></head><body style="font-family:'Century Gothic'"><h1 style="text-align:center;"> company </h1><h2 style="font-size:14px;">Name : name <br />Company : arch <br />Email : qqq@aaaa.com</h2><p>fin</p></body></html>

and it will be shown when receiving the email.

Hope it'll help someone else.




回答2:


Alternately you can use a Velocity template with your Mule application.
Velocity is a Java-based template engine and can be used to send formatted email.
You can also use various HTML tags to format your content
ref :- https://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html



来源:https://stackoverflow.com/questions/26178799/sending-formatted-mails-with-mule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!