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:
Java Program to Check if a Directed Graph is a Tree or Not Using DFS
Java Program to Represent Graph Using Adjacency List
String Operations with Java Streams
Java Program to Find k Numbers Closest to Median of S, Where S is a Set of n Numbers
Disable Spring Data Auto Configuration
Getting the Size of an Iterable in Java
Guide to Spring @Autowired
Spring Cloud – Adding Angular
Các nguyên lý thiết kế hướng đối tượng – SOLID
Java Stream Filter with Lambda Expression
How to Round a Number to N Decimal Places in Java
A Guide to JUnit 5 Extensions
Using the Not Operator in If Conditions in Java
Java Program to Implement the Bin Packing Algorithm
Java Program to Implement Direct Addressing Tables
The Modulo Operator in Java
Java – Convert File to InputStream
Java List UnsupportedOperationException
Server-Sent Events in Spring
Guide to CountDownLatch in Java
Custom Thread Pools In Java 8 Parallel Streams
Guide to BufferedReader
Java Program to Implement Fermat Factorization Algorithm
Annotation trong Java 8
Composition, Aggregation, and Association in Java
Introduction to the Java NIO Selector
Mảng (Array) trong Java
Tìm hiểu cơ chế Lazy Evaluation của Stream trong Java 8
Logout in an OAuth Secured Application
Java Program to Implement Max Heap
Deque và ArrayDeque trong Java
Map Interface trong java