Here you can find the source of sendEmail(String to, String from, String subject, String text)
public static void sendEmail(String to, String from, String subject, String text) throws MessagingException
//package com.java2s; //License from project: Open Source License import javax.mail.*; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; import java.util.Properties; public class Main { public static void sendEmail(String to, String from, String subject, String text) throws MessagingException { Properties props = new Properties(); props.put("mail.smtp.host", "localhost"); props.put("mail.smtp.port", "35"); Session session = Session.getDefaultInstance(props); try {/* www . j a v a 2 s .c om*/ Message message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to)); message.setSubject(subject); message.setText(text); Transport.send(message); } catch (MessagingException e) { throw new RuntimeException(e); } } }