简体   繁体   English

将html添加到xml属性文件中以在Java中发送电子邮件

[英]add html to xml properties file for email in java

I want to send html email.I am using spring framework Mailsender class to send email and there is a email_en.xml file which contains the content which is something like 我想发送HTML电子邮件。我正在使用Spring Framework Mailsender类发送电子邮件,并且有一个email_en.xml文件,其中包含类似以下内容的内容

  <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties [ <!ELEMENT properties ( comment?, entry* ) > <!ATTLIST properties version CDATA #FIXED "1.0"> <!ELEMENT comment (#PCDATA) > <!ELEMENT entry (#PCDATA) > <!ATTLIST entry key CDATA #REQUIRED> ]> <properties> <entry key="subject"> email </entry> <entry key="to"> test@test.com </entry> <entry key="name"> Garry </entry> <entry key="body"> Dear User, <![CDATA[ Dear User, <b>This is your email for reference</b> 
    ]]>
    </entry>
    </properties>

So can I add html tags to this file I tried but it does not work. 所以我可以将html标签添加到我尝试过的此文件中,但是它不起作用。 I have also added [CDATA[ ]] tag but it still not working. 我还添加了[CDATA []]标记,但仍无法正常工作。

Anyone can give me some idea 任何人都可以给我一些想法

Most likely you are using just MailSender and sending simple e-mail messages. 您很可能仅使用MailSender并发送简单的电子邮件。 In order to handle HTML content you should use JavaMailSender which offers you possibility to send MimeMessage . 为了处理HTML内容,您应该使用JavaMailSender ,它使您可以发送MimeMessage

This Spring e-mail tutorial describes the differences, and how to correctly prepare e-mail messages (it's for version 2.xx, but should be applicable to 3.xx). Spring电子邮件教程描述了这些区别以及如何正确准备电子邮件(适用于2.xx版,但应适用于3.xx版)。

If you are using MimeMessageHelper, don't forget to set the HTML flag to true when calling #setText method. 如果使用的是MimeMessageHelper,请不要忘记在调用#setText方法时将HTML标志设置为true。

PS It seems that you are using your custom utility to parse XML messages and turn them into Message beans. PS似乎您正在使用自定义实用程序来解析XML消息并将其转换为Message Bean。 Review your code and make sure that appropriate setters are called since properties in your XML message doesn't match property names in MailMessage . 查看您的代码,并确保调用了适当的setter,因为XML消息中的属性与MailMessage中的属性名称不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM