Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

Fix for email notifications connection issue (#1053)

Rich Turner8c0f74770973
diff --git a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java
index 0e64e5924..0398e2b74 100644
--- a/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java
+++ b/manager/src/main/java/org/openremote/manager/notification/EmailNotificationHandler.java
@@ -108,12 +108,12 @@ public class EmailNotificationHandler implements NotificationHandler {
mailTransport = mailSession.getTransport(protocol);
mailTransport.connect();
valid = mailTransport.isConnected();
- } catch (Exception e) {
- valid = false;
try {
mailTransport.close();
} catch (Exception ignored) {
}
+ } catch (Exception e) {
+ valid = false;
LOG.log(Level.SEVERE, "Failed to connect to SMTP server so disabling email notifications", e);
}
@@ -380,6 +380,9 @@ public class EmailNotificationHandler implements NotificationHandler {
protected NotificationSendResult sendMessage(Message email) {
try {
+ if (!mailTransport.isConnected()) {
+ mailTransport.connect();
+ }
mailTransport.sendMessage(email, email.getAllRecipients());
return NotificationSendResult.success();
} catch (Exception e) {