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);
Done! Happy Coding!
Related posts:
A Guide to TreeSet in Java
Autoboxing và Unboxing trong Java
Custom JUnit 4 Test Runners
Updating your Password
Understanding Memory Leaks in Java
Converting Between a List and a Set in Java
Java Program to Find the Shortest Path from Source Vertex to All Other Vertices in Linear Time
Quick Guide on Loading Initial Data with Spring Boot
Guide to ThreadLocalRandom in Java
Java 14 Record Keyword
Java Program to Evaluate an Expression using Stacks
Removing all Nulls from a List in Java
Sorting in Java
Introduction to Java Serialization
Java Program to Implement Coppersmith Freivald’s Algorithm
Receive email by java client
Introduction to Spring Boot CLI
Intro to Spring Boot Starters
Tính trừu tượng (Abstraction) trong Java
Java Program to Generate a Random Subset by Coin Flipping
Java Program to Search Number Using Divide and Conquer with the Aid of Fibonacci Numbers
How to Get the Last Element of a Stream in Java?
Java Program to Implement Word Wrap Problem
Hướng dẫn Java Design Pattern – Facade
Java Program to Implement Splay Tree
Java Program to Describe the Representation of Graph using Adjacency List
Spring Data MongoDB – Indexes, Annotations and Converters
Optional trong Java 8
HttpClient 4 – Follow Redirects for POST
Send email with authentication
Từ khóa static và final trong java
Java toString() Method