diff --git a/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java b/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java index a514f10d8b8..3e0e5cb4d42 100644 --- a/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java +++ b/src/main/java/org/elasticsearch/watcher/actions/email/service/Account.java @@ -75,7 +75,7 @@ public class Account { if (profile == null) { profile = config.profile; } - transport.connect(config.smtp.host, config.smtp.port, user, new String(password)); + transport.connect(config.smtp.host, config.smtp.port, user, password != null ? new String(password) : null); try { MimeMessage message = profile.toMimeMessage(email, session); @@ -88,12 +88,10 @@ public class Account { } transport.sendMessage(message, message.getAllRecipients()); } finally { - if (transport != null) { - try { - transport.close(); - } catch (MessagingException me) { - logger.error("failed to close email transport for account [" + config.name + "]"); - } + try { + transport.close(); + } catch (MessagingException me) { + logger.error("failed to close email transport for account [" + config.name + "]"); } } return email;