Guest User

Untitled

a guest
Nov 15th, 2017
621
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. package org.millet.sendmail;
  2.  
  3. import java.util.*;
  4. import javax.mail.*;
  5. import javax.mail.internet.*;
  6. import javax.activation.*;
  7.  
  8. /**
  9. * Hello world!
  10. *
  11. */
  12. public class App {
  13.  
  14. public static void main(String [] args) {
  15. String username = "collectionspace.lyrasis@gmail.com";
  16. String password = "CSpace11-GG";
  17. String recipient = "remillet@gmail.com";
  18.  
  19. Properties props = new Properties();
  20.  
  21. props.put("mail.smtp.host", "smtp.gmail.com");
  22. props.put("mail.from", "collectionspace.lyrasis@gmail.com");
  23. props.put("mail.smtp.starttls.enable", "true");
  24. props.put("mail.smtp.port", "587");
  25. props.setProperty("mail.debug", "true");
  26.  
  27. Session session = Session.getInstance(props, null);
  28. MimeMessage msg = new MimeMessage(session);
  29.  
  30. try {
  31. msg.setRecipients(Message.RecipientType.TO, recipient);
  32. msg.setSubject("JavaMail hello world example");
  33. msg.setSentDate(new Date());
  34. msg.setText("Hello, world!\n");
  35.  
  36. Transport transport = session.getTransport("smtp");
  37.  
  38. transport.connect(username, password);
  39. transport.sendMessage(msg, msg.getAllRecipients());
  40. transport.close();
  41. } catch (Exception e) {
  42. System.err.println(e.getMessage());
  43. }
  44. }
  45. }
Add Comment
Please, Sign In to add comment