Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. private Session getSession(String smtpHost, String smtpPort, final String smtpUser, final String smtpPassword,
  2. String encryption, String auth, String trust, String debug) {
  3. logger.debug("smtpHost = " + smtpHost);
  4. logger.debug("smtpPort = " + smtpPort);
  5. logger.debug("smtpUser = " + smtpUser);
  6. logger.debug("smtpPass = " + smtpPassword);
  7. logger.debug("encryption = " + encryption);
  8. logger.debug("auth = " + auth);
  9. logger.debug("trust = " + trust);
  10. logger.debug("debug = " + debug);
  11.  
  12. Properties properties = new Properties();
  13. properties.put("mail.smtp.host", smtpHost);
  14. properties.put("mail.smtp.port", smtpPort);
  15. if (!Strings.isNullOrEmpty(auth)) {
  16. properties.put("mail.smtp.auth", auth);
  17. }
  18. if (!Strings.isNullOrEmpty(trust)) {
  19. properties.put("mail.smtp.ssl.trust", trust);
  20. }
  21. if (!Strings.isNullOrEmpty(debug)) {
  22. properties.put("mail.debug", debug);
  23. }
  24. if (Constants.ENCRYPTION_TLS.equalsIgnoreCase(encryption)) {
  25. properties.put("mail.smtp.starttls.enable", "true");
  26. }
  27. logger.debug("Result properties: {}", properties.toString());
  28.  
  29. if (Strings.isNullOrEmpty(smtpUser)) {
  30. return Session.getInstance(properties);
  31. } else {
  32. return Session.getInstance(properties, new javax.mail.Authenticator() {
  33. protected PasswordAuthentication getPasswordAuthentication() {
  34. return new PasswordAuthentication(smtpUser, smtpPassword);
  35. }
  36. });
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement