Advertisement
Guest User

Untitled

a guest
Oct 5th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. if(action.equals("buy")){
  2. String to = (String)session.getAttribute("user");
  3. //Get the session object
  4. Properties props = new Properties();
  5. props.put("mail.smtp.host", "smtp.gmail.com");
  6. props.put("mail.smtp.socketFactory.port", "465");
  7. props.put("mail.smtp.socketFactory.class",
  8. "javax.net.ssl.SSLSocketFactory");
  9. props.put("mail.smtp.auth", "true");
  10. props.put("mail.smtp.port", "465");
  11.  
  12. Session session2 = Session.getInstance(props,
  13. new javax.mail.Authenticator() {
  14. protected PasswordAuthentication getPasswordAuthentication() {
  15. return new PasswordAuthentication("henri.tuan77@gmail.com","Dumbledore77");//change accordingly
  16. }
  17. });
  18.  
  19. //compose message
  20. try {
  21. MimeMessage message = new MimeMessage(session2);
  22. message.setFrom(new InternetAddress("henri.tuan77@gmail.com"));//change accordingly
  23. message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
  24. message.setSubject("Hello");
  25. message.setText("Testing.......");
  26.  
  27. //send message
  28. Transport.send(message);
  29.  
  30. System.out.println("message sent successfully");
  31.  
  32. } catch (MessagingException e) {
  33. throw new RuntimeException(e);
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement