Guest User

Untitled

a guest
Jan 20th, 2018
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. String to = "abc@example.com";
  2. String user = "sp@example.com";
  3. String pass = "1234";
  4. Properties props = new Properties();
  5. props.put("mail.smtp.host", "smtp.example.com");
  6. props.put("mail.smtp.port", "587");
  7. props.put("mail.smtp.auth", "true");
  8. props.put("mail.smtp.starttls.enable", "true");
  9. Session session = Session.getInstance(props,new javax.mail.Authenticator()
  10. {
  11. protected PasswordAuthentication getPasswordAuthentication()
  12. {
  13. return new PasswordAuthentication(user,pass);
  14. }
  15. });
  16.  
  17. session.setDebug(true);
  18.  
  19.  
  20.  
  21. try
  22. {
  23. /* Create an instance of MimeMessage,
  24. it accept MIME types and headers
  25. */
  26. MimeMessage message = new MimeMessage(session);
  27. message.setFrom(new InternetAddress(user));
  28. message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));
  29. message.setSubject(sub);
  30. message.setText(msg);
  31. /* Transport class is used to deliver the message to the recipients */
  32. Transport.send(message);
  33. }
  34. catch(Exception e)
  35. {
  36. e.printStackTrace();
  37. }
Add Comment
Please, Sign In to add comment