Here you can find the source of sendEmail(String toAddress, String subject, String message)
public static void sendEmail(String toAddress, String subject, String message) throws AddressException, MessagingException
//package com.java2s; //License from project: Apache License import java.util.Date; import java.util.Properties; import javax.mail.Authenticator; 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 sendEmail(String toAddress, String subject, String message) throws AddressException, MessagingException { final String userName = "idesaniv@gmail.com"; final String password = "26577141"; String host = "smtp.gmail.com", port = "25"; // sets SMTP server properties Properties properties = new Properties(); properties.put("mail.transport.protocol", "smtp"); properties.put("mail.smtp.host", host); properties.put("mail.smtp.port", port); properties.put("mail.smtp.auth", "true"); properties.put("mail.smtp.starttls.enable", "true"); // creates a new session with an authenticator Authenticator auth = new Authenticator() { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(userName, password); }// w w w .j a v a 2 s .com }; Session session = Session.getInstance(properties, auth); // creates a new e-mail message Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress(userName)); InternetAddress[] toAddresses = { new InternetAddress(toAddress) }; msg.setRecipients(Message.RecipientType.TO, toAddresses); msg.setSubject(subject); msg.setSentDate(new Date()); msg.setText(message); // sends the e-mail Transport.send(msg); } }