[logback-user] SMTPAppender on windows host can't connect to Amazon AWS smtps server

Olexandr Demura oleksander.demura at gmail.com
Thu May 4 07:39:12 CEST 2017


Hi, guys.

I had problem sending error mail notifications on amazon aws windows
instance,
while regular mail was fine and linux instance (w\ newer tomcat as well)
was fine.

Since I already had my own Suspendable- and Batching- extensions of
SMTPAppender,
I changed Session and Transport handling to overcome it, see introduced
methods below.
But I wonder if I missed something which could be done thru config.
Options I use are
<SSL>true</SSL>
<smtpHost>email-smtp.eu-west-1.amazonaws.com</smtpHost>
<smtpPort>465</smtpPort>
<username>...</username>
<password>...</password>
<from>...</from>
<to>...</to>

protected void put(Properties props, String key, String value) {
    if (value != null) {
        String key1 = !isSSL() ? key : key.replace(".smtp.", ".smtps.");
        props.put(key1, value);
    }
}
protected Session rebuildSessionFromProperties() {
    Properties props = new Properties(OptionHelper.getSystemProperties());
    put(props, "mail.smtp.localhost", getLocalhost());
    if (isSTARTTLS() && isSSL()) {
        addError("Both SSL and StartTLS cannot be enabled simultaneously");
    } else if (isSTARTTLS()) {
        props.put("mail.smtp.starttls.enable", "true");
    } else if (isSSL()) {
        props.put("mail.smtps.ssl.enable", "true");
    }
    return Session.getInstance(props);
}


protected void sendMessage(MimeMessage mimeMsg)
        throws MessagingException {
    addInfo("About to send out SMTP message \"" + mimeMsg.getSubject()
        + "\" to " + Arrays.asList(mimeMsg.getAllRecipients()));
    mimeMsg.saveChanges();
    Transport transport = session.getTransport(isSSL() ? "smtps" : "smtp");
    if (getUsername() == null) {
        transport.connect();
    } else if (getSmtpHost() == null) {
        transport.connect(getUsername(), getPassword());
    } else {
        transport.connect(getSmtpHost(), getSmtpPort(), getUsername(),
getPassword());
    }
    try {
        transport.sendMessage(mimeMsg, mimeMsg.getAllRecipients());
    } finally {
        if (transport.isConnected()) {
            transport.close();
        }
    }
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.qos.ch/pipermail/logback-user/attachments/20170504/6d56ac19/attachment.html>


More information about the logback-user mailing list