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:
Multi Dimensional ArrayList in Java
Exception Handling in Java
Checked and Unchecked Exceptions in Java
Runnable vs. Callable in Java
Java Program to Implement Graph Structured Stack
Overview of Spring Boot Dev Tools
Easy Ways to Write a Java InputStream to an OutputStream
Java Program to Create the Prufer Code for a Tree
Java Program to Perform the Unique Factorization of a Given Number
Java Program to Check Whether an Undirected Graph Contains a Eulerian Cycle
Java Program to Implement DelayQueue API
Apache Camel with Spring Boot
Java Program to Implement Interpolation Search Algorithm
Overflow and Underflow in Java
Java Program to Delete a Particular Node in a Tree Without Using Recursion
Java Program to Implement Shell Sort
String Operations with Java Streams
Java Program to Implement Sorted Array
Returning Custom Status Codes from Spring Controllers
Java Program to Implement Binomial Tree
Thực thi nhiều tác vụ cùng lúc như thế nào trong Java?
Java Program to Solve any Linear Equations
Java Program to Perform Postorder Non-Recursive Traversal of a Given Binary Tree
Java Program to Find Number of Spanning Trees in a Complete Bipartite Graph
Generating Random Numbers in a Range in Java
Java Program to Implement RoleList API
@Order in Spring
Java Program to Implement Min Heap
REST Web service: HTTP Status Code và xử lý ngoại lệ RESTful web service với Jersey 2.x
Daemon Threads in Java
Java Program to Implement Threaded Binary Tree
Jackson – Change Name of Field