使用Mule发送格式化的邮件

时间:2014-10-03 12:19:09

标签: java email smtp format mule

我正在使用Mule发送电子邮件。我需要在我发送的文本中添加格式。 邮件的内容是有效负载,其中包含我在Java方法中形成的字符串,并使用表达式转换器发送到流。 我需要为该String添加格式:粗体,下划线,颜色.... 我该怎么做?

这是我的流程的摘录:

   <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" />

我已尝试过这个,但它不起作用。

<!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>

提前致谢。

2 个答案:

答案 0 :(得分:7)

我解决了。 我错过了将smtp:connector 中的内容类型设置为smtp:outbpund-endbound 中的 mime-type作为要工作的text / html。 这是正确的代码:

<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"/>

使用此配置,您可以在文本中使用html,如下所示

<!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>

并在收到电子邮件时显示。

希望它能帮助别人。

答案 1 :(得分:0)

或者,您可以在您的Mule应用程序中使用Velocity模板 Velocity是一个基于Java的模板引擎,可用于发送格式化的电子邮件 您还可以使用各种HTML标记来格式化您的内容 参考: - https://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html