Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private Session getSession(String smtpHost, String smtpPort, final String smtpUser, final String smtpPassword,
- String encryption, String auth, String trust, String debug) {
- logger.debug("smtpHost = " + smtpHost);
- logger.debug("smtpPort = " + smtpPort);
- logger.debug("smtpUser = " + smtpUser);
- logger.debug("smtpPass = " + smtpPassword);
- logger.debug("encryption = " + encryption);
- logger.debug("auth = " + auth);
- logger.debug("trust = " + trust);
- logger.debug("debug = " + debug);
- Properties properties = new Properties();
- properties.put("mail.smtp.host", smtpHost);
- properties.put("mail.smtp.port", smtpPort);
- if (!Strings.isNullOrEmpty(auth)) {
- properties.put("mail.smtp.auth", auth);
- }
- if (!Strings.isNullOrEmpty(trust)) {
- properties.put("mail.smtp.ssl.trust", trust);
- }
- if (!Strings.isNullOrEmpty(debug)) {
- properties.put("mail.debug", debug);
- }
- if (Constants.ENCRYPTION_TLS.equalsIgnoreCase(encryption)) {
- properties.put("mail.smtp.starttls.enable", "true");
- }
- logger.debug("Result properties: {}", properties.toString());
- if (Strings.isNullOrEmpty(smtpUser)) {
- return Session.getInstance(properties);
- } else {
- return Session.getInstance(properties, new javax.mail.Authenticator() {
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication(smtpUser, smtpPassword);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement