Here you can find the source of sendMail(String host, int port, String username, String password, String recipients, String subject, String content, String from)
public static void sendMail(String host, int port, String username, String password, String recipients, String subject, String content, String from) throws AddressException, MessagingException
//package com.java2s; //License from project: Open Source License import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.AddressException; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class Main { public static void sendMail(String host, int port, String username, String password, String recipients, String subject, String content, String from) throws AddressException, MessagingException { Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", port); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); }/*ww w. j a v a 2 s. c o m*/ }); Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients)); message.setSubject(subject); message.setText(content); Transport.send(message); } }