Advertisement
Guest User

Untitled

a guest
Nov 12th, 2015
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. final String username = "email@gmail.com";
  2.         final String password = "pass";
  3.  
  4.         Properties props = new Properties();
  5.         props.put("mail.smtp.auth", "true");
  6.         props.put("mail.smtp.starttls.enable", "true");
  7.         props.put("mail.smtp.host", "smtp.gmail.com");
  8.         props.put("mail.smtp.port", "587");
  9.  
  10.         Session session = Session.getInstance(props,
  11.                 new javax.mail.Authenticator() {
  12.                     protected PasswordAuthentication getPasswordAuthentication() {
  13.                         return new PasswordAuthentication(username, password);
  14.                     }
  15.                 });
  16.  
  17.         try {
  18.  
  19.             Message message = new MimeMessage(session);
  20.             message.setFrom(new InternetAddress("email@gmail.com"));
  21.             message.setRecipients(Message.RecipientType.TO,
  22.                     InternetAddress.parse("mynumber@vtext.com"));
  23.             message.setSubject("");
  24.             message.setText("test1");
  25.  
  26.             Transport.send(message);
  27.             log("sent msg");
  28.         } catch (MessagingException e) {
  29.             throw new RuntimeException(e);
  30.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement