Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Email Content in HTML

Tags:

java

email

spring

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.

like image 738
Arun Kumar Avatar asked Dec 28 '11 05:12

Arun Kumar


1 Answers

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);
like image 69
CoolBeans Avatar answered Oct 01 '22 00:10

CoolBeans