List of usage examples for java.net Authenticator getPasswordAuthentication
protected PasswordAuthentication getPasswordAuthentication()
From source file:au.aurin.org.controller.RestController.java
private Session getSession() { final Authenticator authenticator = new Authenticator(); final Properties properties = new Properties(); properties.setProperty("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserName()); properties.setProperty("mail.smtp.auth", classmail.getAuth().toString()); properties.setProperty("mail.smtp.host", classmail.getHost()); properties.setProperty("mail.smtp.port", classmail.getPort()); return Session.getInstance(properties, authenticator); }
From source file:org.snopoke.util.Emailer.java
/** * Create the mail session with authentication and properties for SSL/TLS * etc.//w w w. j a v a 2s. co m * * @return configured mail session */ private Session getSession() { Properties properties = new Properties(); Authenticator authenticator = new Authenticator(); if (username != null && password != null) { properties.put("mail.smtp.submitter", authenticator.getPasswordAuthentication().getUserName()); properties.put("mail.smtp.auth", "true"); } properties.put("mail.smtp.host", host); properties.put("mail.smtp.port", port); properties.put("mail.smtp.socketFactory.port", port); properties.put("mail.smtp.socketFactory.fallback", "false"); if (useSSL) properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); if (useTLS) properties.put("mail.smtp.starttls.enable", "true"); if (debug) { properties.put("mail.smtp.ssl.checkserveridentity", "false"); properties.put("mail.smtp.ssl.trust", "*"); properties.put("mail.debug", "true"); } return Session.getInstance(properties, authenticator); }