简体   繁体   中英

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

  <?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. I have also added [CDATA[ ]] tag but it still not working.

Anyone can give me some idea

Most likely you are using just MailSender and sending simple e-mail messages. In order to handle HTML content you should use JavaMailSender which offers you possibility to send 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).

If you are using MimeMessageHelper, don't forget to set the HTML flag to true when calling #setText method.

PS It seems that you are using your custom utility to parse XML messages and turn them into Message beans. Review your code and make sure that appropriate setters are called since properties in your XML message doesn't match property names in MailMessage .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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