List of usage examples for javax.mail PasswordAuthentication getUserName
public String getUserName()
From source file:org.cloudcoder.healthmonitor.HealthMonitor.java
/** * Create a mail Session based on information in the * given {@link HealthMonitorConfig}.//from w w w. j a va 2 s . c o m * * @param config the {@link HealthMonitorConfig} * @return the mail Session */ private Session createMailSession(HealthMonitorConfig config) { final PasswordAuthentication passwordAuthentication = new PasswordAuthentication(config.getSmtpUsername(), config.getSmtpPassword()); Properties properties = new Properties(); properties.putAll(System.getProperties()); properties.setProperty("mail.smtp.submitter", passwordAuthentication.getUserName()); properties.setProperty("mail.smtp.auth", "true"); properties.setProperty("mail.smtp.host", config.getSmtpServer()); properties.setProperty("mail.smtp.port", String.valueOf(config.getSmtpPort())); properties.setProperty("mail.smtp.starttls.enable", String.valueOf(config.isSmtpUseTLS())); return Session.getInstance(properties, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return passwordAuthentication; } }); }