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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With