Martin Peřina has uploaded a new change for review.

Change subject: tools: Fixes SMTP configuration in notifier
......................................................................

tools: Fixes SMTP configuration in notifier

Fixes proper settings of JavaMail properties to support SMTPS protocol.

Change-Id: I9d5d898549f43c18afbc568413f7b9a71b4f5a28
Bug-Url: https://bugzilla.redhat.com/1020900
Signed-off-by: Martin Perina <mper...@redhat.com>
---
M 
backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
1 file changed, 7 insertions(+), 18 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/27/20427/1

diff --git 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
index e746fa2..60675ef 100644
--- 
a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
+++ 
b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java
@@ -29,7 +29,6 @@
     private InternetAddress from = null;
     private InternetAddress replyTo = null;
     private boolean isBodyHtml = false;
-    private boolean isSSL = false;
     private EmailAuthenticator auth;
 
     /**
@@ -40,19 +39,15 @@
     public JavaMailSender(NotificationProperties aMailProps) {
         Properties mailSessionProps = setCommonProperties(aMailProps);
 
-        mailSessionProps.put("mail.host", 
aMailProps.getProperty(NotificationProperties.MAIL_SERVER));
+        mailSessionProps.put("mail.smtp.host", 
aMailProps.getProperty(NotificationProperties.MAIL_SERVER));
         // enable SSL
         if (aMailProps.getBoolean(NotificationProperties.MAIL_ENABLE_SSL, 
false)) {
-            mailSessionProps.put("mail.transport.protocol", "smtps");
             mailSessionProps.put("mail.smtp.port", 
aMailProps.getProperty(NotificationProperties.MAIL_PORT_SSL));
-            mailSessionProps.put("mail.smtps.socketFactory.port", 
aMailProps.getProperty(NotificationProperties.MAIL_PORT_SSL));
-            mailSessionProps.put("mail.smtps.auth", "true");
-            mailSessionProps.put("mail.smtps.socketFactory.class", 
"javax.net.ssl.SSLSocketFactory");
-            mailSessionProps.put("mail.smtps.socketFactory.fallback", false);
-
-            this.isSSL = true;
+            mailSessionProps.put("mail.smtp.auth", "true");
+            mailSessionProps.put("mail.smtp.socketFactory.class", 
"javax.net.ssl.SSLSocketFactory");
+            mailSessionProps.put("mail.smtp.socketFactory.fallback", false);
+            mailSessionProps.put("mail.smtp.socketFactory.port", 
aMailProps.getProperty(NotificationProperties.MAIL_PORT_SSL));
         } else {
-            mailSessionProps.put("mail.transport.protocol", "smtp");
             mailSessionProps.put("mail.smtp.port", 
aMailProps.getProperty(NotificationProperties.MAIL_PORT));
         }
 
@@ -64,7 +59,6 @@
         } else {
             this.session = Session.getInstance(mailSessionProps);
         }
-
     }
 
     /**
@@ -155,13 +149,7 @@
                 msg.setText(messageBody);
             }
             msg.setSentDate(new Date());
-            if (isSSL) {
-                Transport transport = session.getTransport("smtps");
-                transport.connect();
-                transport.sendMessage(msg, new Address[] { address });
-            } else {
-                Transport.send(msg);
-            }
+            Transport.send(msg);
         } catch (MessagingException mex) {
             StringBuilder errorMsg = new StringBuilder("Failed to send message 
");
             if (from != null) {
@@ -190,6 +178,7 @@
             this.password = password;
         }
 
+        @Override
         protected PasswordAuthentication getPasswordAuthentication() {
             return new PasswordAuthentication(userName, password);
         }


-- 
To view, visit http://gerrit.ovirt.org/20427
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9d5d898549f43c18afbc568413f7b9a71b4f5a28
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Martin Peřina <mper...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to