Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. public class MailSender {
  2.  
  3. private final static String USERNAME = "mail-box adres";
  4. private final static String PASSWORD = "mail-box password";
  5.  
  6. Connection connection;
  7.  
  8. public MailSender(Connection connect) {
  9. connection=connect;
  10. }
  11.  
  12. public void send(List<Message> messageList) throws MessagingException {
  13. if (messageList==null) throw new NullPointerException("Message error");
  14.  
  15. MailRepository dataModificator=new MailRepository(connection);
  16.  
  17. Properties props = new Properties();
  18. props.put("mail.smtp.starttls.enable", "true");
  19. props.put("mail.smtp.auth", "true");
  20. props.put("mail.smtp.host", "smtp.gmail.com");
  21. props.put("mail.smtp.port", "587");
  22. props.put("mail.smtp.ssl.trust", "smtp.gmail.com");
  23.  
  24. Session session = Session.getInstance(props,
  25. new javax.mail.Authenticator() {
  26. protected PasswordAuthentication getPasswordAuthentication() {
  27. return new PasswordAuthentication(USERNAME, PASSWORD);
  28. }
  29. });
  30.  
  31. public class MyClass {
  32.  
  33. private static final Properties props = new Properties(){{
  34. put("mail.smtp.starttls.enable", "true");
  35. put("mail.smtp.auth", "true");
  36. put("mail.smtp.host", "smtp.gmail.com");
  37. put("mail.smtp.port", "587");
  38. put("mail.smtp.ssl.trust", "smtp.gmail.com");
  39. }};
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement