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:
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);