Sending Email Content in HTML

冷暖自知 提交于 2021-01-21 06:53:32

问题


I have to send an email having all content in html that can be displayed in email as a HTML. I am able to send the email with JavaMailSenderImpl of Spring Framework with SimpleMailMessage but the email I send is displayed in plain html text like following

<html><body><h1>Hello</h1></body></html>

and not in form of HTML page.

Please tell the way how can i send it as HTML and how it can be displayed in form of HTML.


回答1:


If you are using java mail directly, you need to set the content type to html using the setContent() method. MimeMessage.setContent("<html> <body><h1>Hello </h1> </body></html>", "text/html");

Or if you are using Spring framework's MimeMessageHelper you can use MimeMessageHelper.setText(emailContent,true) method. The boolean true flag indicates html content. For instance:

    mimeMessageHelper.setTo("some@someone");
    mimeMessageHelper.setReplyTo("some@someone");
    mimeMessageHelper.setFrom("some@someone");
    mimeMessageHelper.setSubject("someSubject");
    mimeMessageHelper.setText("<html> <body><h1>Hello </h1> </body></html>",true);


来源:https://stackoverflow.com/questions/8652055/sending-email-content-in-html

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