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 JUnit 5
Java Program to Create a Random Graph Using Random Edge Generation
Java Program to Implement ArrayBlockingQueue API
Từ khóa this và super trong Java
Java Program to Implement Queue using Linked List
Guide to the Volatile Keyword in Java
Spring – Injecting Collections
Hướng dẫn Java Design Pattern – Decorator
Spring Cloud Series – The Gateway Pattern
Java Program to add two large numbers using Linked List
Merging Two Maps with Java 8
Java Program to Implement Hash Tables Chaining with Doubly Linked Lists
Java Program to Implement Stack API
Mapping Nested Values with Jackson
Java Program to Check for balanced parenthesis by using Stacks
Java Program for Douglas-Peucker Algorithm Implementation
Java – Delete a File
Java 8 StringJoiner
Java Program to Implement Dijkstra’s Algorithm using Priority Queue
Quick Intro to Spring Cloud Configuration
Using JWT with Spring Security OAuth (legacy stack)
HttpClient 4 – Follow Redirects for POST
Java Program to Implement Wagner and Fisher Algorithm for online String Matching
Java Program to Implement JobStateReasons API
Java Program to Generate Random Hexadecimal Byte
Weak References in Java
Giới thiệu HATEOAS
Call Methods at Runtime Using Java Reflection
Filtering a Stream of Optionals in Java
Java Program to Implement Counting Sort
Java Collections Interview Questions
Guide to the Java Queue Interface