Martin Peřina has uploaded a new change for review. Change subject: tools: Adds support for SMTP with STARTTLS to notifier ......................................................................
tools: Adds support for SMTP with STARTTLS to notifier Adds support for sending emails using SMTP with STARTTLS. Change-Id: I751a0db149cbd217728c036a65f7fadc6da4cdf9 Signed-off-by: Martin Perina <mper...@redhat.com> --- M backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java M backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/sender/mail/JavaMailSender.java M packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in 3 files changed, 27 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/97/22297/1 diff --git a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java index 74d9dbd..0192706 100644 --- a/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java +++ b/backend/manager/tools/src/main/java/org/ovirt/engine/core/notifier/utils/NotificationProperties.java @@ -35,6 +35,11 @@ public static final String MAIL_SMTP_ENCRYPTION_SSL = "ssl"; /** + * SMTP transport encryption using TLS (SMTP with STARTTLS) + */ + public static final String MAIL_SMTP_ENCRYPTION_TLS = "tls"; + + /** * Service parameters */ public static final String DAYS_TO_KEEP_HISTORY = "DAYS_TO_KEEP_HISTORY"; @@ -137,10 +142,11 @@ if (!isSmtpEncryptionOptionValid()) { throw new IllegalArgumentException( String.format( - "Check configuration file, '%s' value has to be one of: '%s', '%s'.", + "Check configuration file, '%s' value has to be one of: '%s', '%s', '%s'.", NotificationProperties.MAIL_SMTP_ENCRYPTION, NotificationProperties.MAIL_SMTP_ENCRYPTION_NONE, - NotificationProperties.MAIL_SMTP_ENCRYPTION_SSL + NotificationProperties.MAIL_SMTP_ENCRYPTION_SSL, + NotificationProperties.MAIL_SMTP_ENCRYPTION_TLS )); } @@ -178,10 +184,11 @@ String emailUser = getProperty(NotificationProperties.MAIL_USER, true); if (StringUtils.isEmpty(emailUser) && (isSmtpEncryptionSsl() + || isSmtpEncryptionTls() || StringUtils.isNotEmpty(getProperty(NotificationProperties.MAIL_PASSWORD, true)))) { throw new IllegalArgumentException( String.format( - "'%s' must be set when SSL is enabled or when password is set", + "'%s' must be set when SSL or TLS is enabled or when password is set", NotificationProperties.MAIL_USER)); } } @@ -203,10 +210,18 @@ } /** + * Returns {@code true}, mail transport encryption type {@link MAIL_SMTP_ENCRYPTION} is set to TLS + * {@link MAIL_SMTP_ENCRYPTION_TLS} + */ + public boolean isSmtpEncryptionTls() { + return MAIL_SMTP_ENCRYPTION_TLS.equals(getProperty(MAIL_SMTP_ENCRYPTION, true)); + } + + /** * Returns {@code true} if mail transport encryption type {@link MAIL_SMTP_ENCRYPTION} is correctly specified, * otherwise {@code false} */ public boolean isSmtpEncryptionOptionValid() { - return isSmtpEncryptionNone() || isSmtpEncryptionSsl(); + return isSmtpEncryptionNone() || isSmtpEncryptionSsl() || isSmtpEncryptionTls(); } } 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 6283583..8e99660 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 @@ -39,12 +39,15 @@ mailSessionProps.put("mail.smtp.host", aMailProps.getProperty(NotificationProperties.MAIL_SERVER)); mailSessionProps.put("mail.smtp.port", aMailProps.getProperty(NotificationProperties.MAIL_PORT)); - // enable SSL + if (aMailProps.isSmtpEncryptionSsl()) { 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)); + } else if (aMailProps.isSmtpEncryptionTls()) { + mailSessionProps.put("mail.smtp.auth", "true"); + mailSessionProps.put("mail.smtp.starttls.enable", "true"); } String password = aMailProps.getProperty(NotificationProperties.MAIL_PASSWORD, true); diff --git a/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in b/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in index 3fba4d2..c835fcf 100644 --- a/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in +++ b/packaging/services/ovirt-engine-notifier/ovirt-engine-notifier.conf.in @@ -46,18 +46,18 @@ # The SMTP mail server address. Required. MAIL_SERVER= -# The SMTP port (usually 25 for plain SMTP, 465 for SMTP with SSL) +# The SMTP port (usually 25 for plain SMTP, 465 for SMTP with SSL, 587 for SMTP with TLS) MAIL_PORT=25 -# Required if SSL enabled to authenticate the user. Used also to specify 'from' user address if mail server +# Required if SSL or TLS enabled to authenticate the user. Used also to specify 'from' user address if mail server # supports, when MAIL_FROM is not set. Address is in RFC822 format MAIL_USER= -# Required to authenticate the user if mail server requires authentication or if SSL is enabled +# Required to authenticate the user if mail server requires authentication or if SSL or TLS is enabled SENSITIVE_KEYS="${SENSITIVE_KEYS},MAIL_PASSWORD" MAIL_PASSWORD= -# Indicates type of encryption (none or ssl) should be used to communicate with mail server. +# Indicates type of encryption (none, ssl or tls) should be used to communicate with mail server. MAIL_SMTP_ENCRYPTION=none # If set to true, sends a message in HTML format. -- To view, visit http://gerrit.ovirt.org/22297 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I751a0db149cbd217728c036a65f7fadc6da4cdf9 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