package sendemail; 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 SendEmail { public static void main(String[] args) throws Exception { final String username = "Firstemail@yahoo.com"; final String password = "password"; Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.mail.yahoo.com"); // props.put("mail.smtp.port", "465"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress("Secondemail@yahoo.com")); message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("Firstemail@yahoo.com")); message.setSubject("Testing Subject"); message.setText("asdasda"); Transport.send(message); System.out.println("Done"); } catch (MessagingException e) { throw new RuntimeException(e); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)