Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. Properties props = new Properties();
  2. props.put("mail.smtp.host" , "smtp.gmail.com");
  3. props.put("mail.stmp.user" , "horiond@gmail.com");
  4.  
  5. //TLS
  6. props.put("mail.smtp.auth", "true");
  7. props.put("mail.smtp.starttls.enable", "true");
  8. props.put("mail.smtp.password", "xxxxx");
  9.  
  10. //SSL
  11. props.put("mail.smtp.socketFactory.port", "465");
  12. props.put("mail.smtp.socketFactory.class",
  13. "javax.net.ssl.SSLSocketFactory");
  14. props.put("mail.smtp.auth", "true");
  15. props.put("mail.smtp.port", "465");
  16.  
  17. Session session = Session.getDefaultInstance( props , null);
  18. String to = "horiond@gmail.com";
  19. String from = "horiond@gmail.com";
  20. String subject = "Testing...";
  21. Message msg = new MimeMessage(session);
  22. try {
  23. msg.setFrom(new InternetAddress(from));
  24. msg.setRecipient(Message.RecipientType.TO,
  25. new InternetAddress(to));
  26. msg.setSubject(subject);
  27. msg.setText("Working fine..!");
  28. Transport transport = session.getTransport("smtp");
  29. transport.connect("smtp.gmail.com" , 465 , "horiondev@gmail.com", "messages3881");
  30. transport.send(msg);
  31. System.out.println("fine!!");
  32. }
  33. catch(Exception exc) {
  34. System.out.println(exc);
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement