Guest User

PathavaPudeMail

a guest
Mar 25th, 2017
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. package pathavapudhemail;
  2.  
  3. import java.util.Properties;
  4.  
  5. import javax.mail.Message;
  6. import javax.mail.MessagingException;
  7. import javax.mail.PasswordAuthentication;
  8. import javax.mail.Session;
  9. import javax.mail.Transport;
  10. import javax.mail.internet.InternetAddress;
  11. import javax.mail.internet.MimeMessage;
  12.  
  13.  
  14.  
  15.  
  16. /**
  17. *
  18. * @author CCL-04
  19. */
  20. public class PathavaPudheMail {
  21.  
  22. /**
  23. * @param args the command line arguments
  24. */
  25. public static void main(String[] args) {
  26. final String username = "katharsuyash9@gmail.com";
  27. final String password = "";
  28.  
  29. Properties props = new Properties();
  30. props.put("mail.smtp.auth", "true");
  31. props.put("mail.smtp.starttls.enable", "true");
  32. props.put("mail.smtp.host", "smtp.gmail.com");
  33. props.put("mail.smtp.port", "587");
  34.  
  35. Session session = Session.getInstance(props,
  36. new javax.mail.Authenticator() {
  37. protected PasswordAuthentication getPasswordAuthentication() {
  38. return new PasswordAuthentication(username, password);
  39. }
  40. });
  41.  
  42. try {
  43.  
  44. Message message = new MimeMessage(session);
  45. message.setFrom(new InternetAddress("katharsuyash9@gmail.com"));
  46. message.setRecipients(Message.RecipientType.TO,
  47. InternetAddress.parse("kkatkar96@gmail.com"));
  48. message.setSubject("Testing Subject");
  49. message.setText("Dear Mail Crawler,"
  50. + "\n\n No spam to my email, please!");
  51.  
  52. Transport.send(message);
  53.  
  54. System.out.println("Done");
  55.  
  56. } catch (MessagingException e) {
  57. throw new RuntimeException(e);
  58. }
  59. }
  60.  
  61. }
Add Comment
Please, Sign In to add comment