How do I send an HTML email? How do I send an HTML email? java java

How do I send an HTML email?


As per the Javadoc, the MimeMessage#setText() sets a default mime type of text/plain, while you need text/html. Rather use MimeMessage#setContent() instead.

message.setContent(someHtmlMessage, "text/html; charset=utf-8");

For additional details, see:


Set content type. Look at this method.

message.setContent("<h1>Hello</h1>", "text/html");


If you are using Google app engine/Java, then use the following...

MimeMessage msg = new MimeMessage(session);msg.setFrom(new InternetAddress(SENDER_EMAIL_ADDRESS, "Admin"));msg.addRecipient(Message.RecipientType.TO,                 new InternetAddress(toAddress, "user");msg.setSubject(subject,"UTF-8");Multipart mp = new MimeMultipart();MimeBodyPart htmlPart = new MimeBodyPart();htmlPart.setContent(message, "text/html");mp.addBodyPart(htmlPart);msg.setContent(mp);Transport.send(msg);