Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. public static void main(String[] args) throws ClassNotFoundException, IOException, ParseException, SQLException, InterruptedException {
  2.        
  3.         final String username = "roomiesender@gmail.com";
  4.         final String password = "Easy1234";
  5.  
  6.         Properties props = new Properties();
  7.         props.put("mail.smtp.auth", "true");
  8.         props.put("mail.smtp.starttls.enable", "true");
  9.         props.put("mail.smtp.host", "smtp.gmail.com");
  10.         props.put("mail.smtp.port", "587");
  11.  
  12.         Session session = Session.getInstance(props,
  13.           new javax.mail.Authenticator() {
  14.             protected PasswordAuthentication getPasswordAuthentication() {
  15.                 return new PasswordAuthentication(username, password);
  16.             }
  17.           });
  18.  
  19.         try {
  20.  
  21.             Message message = new MimeMessage(session);
  22.             message.setFrom(new InternetAddress("roomiesender@gmail.com"));
  23.             message.setRecipients(Message.RecipientType.TO,
  24.                 InternetAddress.parse("vivianecosta2794@gmail.com"));
  25.             message.setSubject("Testing Subject");
  26.             message.setText("Dear Mail Crawler,"
  27.                 + "\n\n No spam to my email, please!");
  28.  
  29.             Transport.send(message);
  30.  
  31.             System.out.println("Done");
  32.  
  33.         } catch (MessagingException e) {
  34.             throw new RuntimeException(e);
  35.         }
  36.        
  37.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement