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:
Guide to UUID in Java
Hướng dẫn Java Design Pattern – Builder
Spring Security Login Page with React
Java Program to Implement Bloom Filter
Java Program to Apply Above-Below-on Test to Find the Position of a Point with respect to a Line
Format ZonedDateTime to String
Apache Commons Collections SetUtils
Guide to Spring Cloud Kubernetes
Java Program to Implement Ternary Search Algorithm
Java Program to Check for balanced parenthesis by using Stacks
Changing Annotation Parameters At Runtime
Hamcrest Collections Cookbook
Testing in Spring Boot
Java Program to find the number of occurrences of a given number using Binary Search approach
Send email with SMTPS (eg. Google GMail)
Spring Boot - Cloud Configuration Server
Lập trình đa luồng với CompletableFuture trong Java 8
Java Program to Perform the Unique Factorization of a Given Number
Java Program to Implement the Program Used in grep/egrep/fgrep
Tạo số và chuỗi ngẫu nhiên trong Java
New Features in Java 8
Queue và PriorityQueue trong Java
Java Program to Check Cycle in a Graph using Topological Sort
Spring MVC Async vs Spring WebFlux
Spring Boot - Rest Controller Unit Test
Compare Two JSON Objects with Jackson
The HttpMediaTypeNotAcceptableException in Spring MVC
An Introduction to ThreadLocal in Java
Jackson Exceptions – Problems and Solutions
Hướng dẫn Java Design Pattern – Flyweight
Using Custom Banners in Spring Boot
StringBuilder vs StringBuffer in Java