Here you can find the source of sendEmail(final String aFromEmailAddr, final String aToEmailAddr, final String aSubject, final String aBody)
public static void sendEmail(final String aFromEmailAddr, final String aToEmailAddr, final String aSubject, final String aBody)
//package com.java2s; /*/*from w w w .jav a 2 s . co m*/ * SwingTech Software - http://cooksarm.sourceforge.net/ * * Copyright (C) 2011 Joe Rice All rights reserved. * * SwingTech Cooks Arm is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by the Free * Software Foundation; either version 3 of the License, or (at your option) any * later version. * * SwingTech Cooks Arm is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * SwingTech Cooks Arm; If not, see <http://www.gnu.org/licenses/>. */ 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.InternetAddress; import javax.mail.internet.MimeMessage; public class Main { static Properties props = new Properties(); public static void sendEmail(final String aFromEmailAddr, final String aToEmailAddr, final String aSubject, final String aBody) { Session session = null; session = Session.getDefaultInstance(props, new javax.mail.Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("jizzoerice@gmail.com", "!amdaman01"); } }); try { final Message message = new MimeMessage(session); message.setFrom(new InternetAddress(aFromEmailAddr)); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(aToEmailAddr)); message.setSubject(aSubject); message.setText(aBody); Transport.send(message); System.out.println("Done"); } catch (final MessagingException e) { System.out.println("WARNING!!!! tried unsucessfully to send email. Details: from: " + aFromEmailAddr + ". to: " + aToEmailAddr + ". subject: " + aSubject + ". body: " + aBody); } } }