Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/main/java/com/socrata/datasync/SMTPMailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,18 @@ public static void send(String recipientEmail, String ccEmail, String title, Str

// Get a Properties object
Properties props = System.getProperties();
props.setProperty("mail.smtps.host", userPrefs.getOutgoingMailServer());
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", userPrefs.getSmtpPort());
String sslPort = userPrefs.getSslPort();

boolean useSSL = !(sslPort.equals(""));

boolean hasPwd = userPrefs.getSmtpPassword() != null && !userPrefs.getSmtpPassword().isEmpty();

if(useSSL) {

props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtp.socketFactory.port", sslPort);
props.setProperty("mail.smtps.auth", "true");
props.setProperty("mail.smtps.host", userPrefs.getOutgoingMailServer());
props.setProperty("mail.smtps.socketFactory.fallback", "false");
props.setProperty("mail.smtps.port", sslPort);
props.setProperty("mail.smtps.socketFactory.class", SSL_FACTORY);
props.setProperty("mail.smtps.socketFactory.port", sslPort);
props.setProperty("mail.smtps.auth", hasPwd ? "true" : "false");
/*
If set to false, the QUIT command is sent and the connection is immediately closed. If set
to true (the default), causes the transport to wait for the response to the QUIT command.
Expand All @@ -83,9 +82,16 @@ to true (the default), causes the transport to wait for the response to the QUIT
http://forum.java.sun.com/thread.jspa?threadID=5205249
smtpsend.java - demo program from javamail
*/
props.put("mail.smtps.quitwait", "false");
props.setProperty("mail.smtps.quitwait", "false");
} else {
props.setProperty("mail.smtp.host", userPrefs.getOutgoingMailServer());
props.setProperty("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.port", userPrefs.getSmtpPort());
props.setProperty("mail.smtp.auth", hasPwd ? "true" : "false");
props.setProperty("mail.smtp.quitwait", "false");
}


Session session = Session.getInstance(props, null);

// -- Create a new message --
Expand All @@ -111,12 +117,14 @@ to true (the default), causes the transport to wait for the response to the QUIT
msg.setText(message, "utf-8");
msg.setSentDate(new Date());

SMTPTransport t = (SMTPTransport)session.getTransport(useSSL ? "smtps" : "smtp");

SMTPTransport t = (SMTPTransport)session.getTransport("smtp");
if (useSSL)
t = (SMTPTransport)session.getTransport("smtps");
if(useSSL || hasPwd) {
t.connect(userPrefs.getOutgoingMailServer(), userPrefs.getSmtpUsername(), userPrefs.getSmtpPassword());
} else {
t.connect();
}

t.connect(userPrefs.getOutgoingMailServer(), userPrefs.getSmtpUsername(), userPrefs.getSmtpPassword());
t.sendMessage(msg, msg.getAllRecipients());
t.close();
}
Expand Down