Mix plain text and HTML content in a mailTag(s): Networking
About cookies on this site
We use cookies to collect and analyze information on site performance and usage,
to provide social media features and to enhance and customize content and advertisements.
Properties props = new Properties();
props.put("mail.smtp.host", "MYMAILSERVER");
Session session = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(session);
InternetAddress from = new InternetAddress("from@me.com");
InternetAddress to = new InternetAddress("to@you.com");
message.setSubject("I am a multipart text/html email" );
message.setFrom(from);
message.addRecipient(Message.RecipientType.TO, to);
Multipart multipart = new MimeMultipart();
// PLAIN TEXT
BodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setText("Here is your plain text message");
multipart.addBodyPart(messageBodyPart);
// HTML TEXT
messageBodyPart = new MimeBodyPart();
String htmlText = "<H1>I am the html part</H1>";
messageBodyPart.setContent(htmlText, "text/html");
multipart.addBodyPart(messageBodyPart);
message.setContent(multipart);
Transport.send(message);