try using setContent instead of setText
so for your example code:
Message msg = new MimeMessage(session1); msg.setFrom(new InternetAddress(" abc@xyz.com ", "Team Application")); msg.addRecipient(Message.RecipientType.TO, new InternetAddress(email, "Dear "+name1+".")); msg.setSubject("Registration confirmation mail"); msg.setContent("Dear <i>"+name1+"</i>,<br>Thanks for registering with us.", "text/html"); Transport.send(msg);
Personally, I use a multi-page message with text and an html version. This is part of my own code:
// Unformatted text version final MimeBodyPart textPart = new MimeBodyPart(); textPart.setText("plain content"); // HTML version final MimeBodyPart htmlPart = new MimeBodyPart(); htmlPart.setContent("<b>html content</b>", "text/html"); // Create the Multipart. Add BodyParts to it. final Multipart mp = new MimeMultipart(); mp.addBodyPart(textPart); mp.addBodyPart(htmlPart); // Set Multipart as the message content msg.setContent(mp);
source share