wrkbrs

[Java] JavaMailSenderImpl 메일 전송 내용 HTML 적용 본문

Java

[Java] JavaMailSenderImpl 메일 전송 내용 HTML 적용

zcarc 2019. 1. 12. 18:36

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.







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