Guest User

Untitled

a guest
Jan 3rd, 2018
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. // packages
  2. // imports
  3.  
  4. public class SendMail {
  5.  
  6. public static void sendMail(double price) {
  7. Properties props = new Properties();
  8.  
  9. props.put("mail.smtp.host", "smtp.gmail.com");
  10. props.put("mail.smtp.socketFactory.port", "465");
  11. props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
  12. props.put("mail.smtp.auth", "true");
  13. props.put("mail.smtp.port", "465");
  14.  
  15. Session session = Session.getDefaultInstance(props,
  16. new javax.mail.Authenticator() {
  17. protected PasswordAuthentication getPasswordAuthentication()
  18. {
  19. return new PasswordAuthentication("mymail@gmail.com", "***"); // here your mail or pass of the test
  20. }
  21. });
  22.  
  23. session.setDebug(true);
  24. try {
  25.  
  26. Message message = new MimeMessage(session);
  27. message.setFrom(new InternetAddress("mymail@gmail.com"));
  28.  
  29. Address[] toUser = InternetAddress
  30. .parse("mymail@gmail.com");
  31. message.setRecipients(Message.RecipientType.TO, toUser);
  32. message.setSubject("Send email with new price");
  33. message.setText("New price is: $"+price);
  34.  
  35. Transport.send(message);
  36. System.out.println("Sending mail completed!!!");
  37. } catch (MessagingException e) {
  38. throw new RuntimeException(e);
  39. }
  40. }
  41.  
  42. }
Add Comment
Please, Sign In to add comment