Here you can find the source of sendEmail(Session session, String fromEmail, String toEmail, String subject, String body)
Parameter | Description |
---|---|
session | a parameter |
toEmail | a parameter |
subject | a parameter |
body | a parameter |
public static void sendEmail(Session session, String fromEmail, String toEmail, String subject, String body)
//package com.java2s; //License from project: Apache License import java.util.Date; import javax.mail.Message; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class Main { /**// w w w . ja v a 2s .c o m * Utility method to send simple HTML email * @param session * @param toEmail * @param subject * @param body */ public static void sendEmail(Session session, String fromEmail, String toEmail, String subject, String body) { try { MimeMessage msg = new MimeMessage(session); //set message headers msg.addHeader("Content-type", "text/HTML; charset=UTF-8"); msg.addHeader("format", "flowed"); msg.addHeader("Content-Transfer-Encoding", "8bit"); msg.setFrom(new InternetAddress(fromEmail, "NoReply-JD")); msg.setReplyTo(InternetAddress.parse("no_reply@journaldev.com", false)); msg.setSubject(subject, "UTF-8"); msg.setText(body, "UTF-8"); msg.setSentDate(new Date()); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toEmail, false)); System.out.println("Message is ready"); Transport.send(msg); System.out.println("EMail Sent Successfully!!"); } catch (Exception e) { e.printStackTrace(); } } }