From dfa5f7550d6b6f2a24c28df6b7380b8db2145b9b Mon Sep 17 00:00:00 2001 From: Martynov Maxim Date: Fri, 28 Feb 2020 12:23:23 +0300 Subject: [PATCH] HCX-47 Fix MailSender usage without auth (#42) --- CHANGELOG.md | 1 + .../latera/bss/connectors/MailSender.groovy | 28 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5b12889..a5035dd0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ v1.4.2 [unreleased] - [#26](https://github.com/latera/camunda-ext/pull/26) Fix passing appCode into hid.Hydra#mainInit method - [#34](https://github.com/latera/camunda-ext/pull/34) Search settlement accounts for base subjects, not personal ones - [#41](https://github.com/latera/camunda-ext/pull/41) Use http-builder-ng-okhttp with PATCH requests support +- [#42](https://github.com/latera/camunda-ext/pull/42) Fix MailSender usage without auth v1.4.1 [2020-02-14] ------------------- diff --git a/src/org/camunda/latera/bss/connectors/MailSender.groovy b/src/org/camunda/latera/bss/connectors/MailSender.groovy index c399e7d0..a42fb5ad 100644 --- a/src/org/camunda/latera/bss/connectors/MailSender.groovy +++ b/src/org/camunda/latera/bss/connectors/MailSender.groovy @@ -18,6 +18,7 @@ import static org.camunda.latera.bss.utils.ListUtil.firstNotNull class MailSender implements AutoCloseable { private String host private Integer port + private Boolean auth private String user private String password private Session session @@ -34,7 +35,7 @@ class MailSender implements AutoCloseable { this.user = execution.getVariable('smtpUser') ?: ENV['SMTP_USER'] this.password = execution.getVariable('smtpPassword') ?: ENV['SMTP_PASSWORD'] - Boolean auth = Boolean.valueOf(firstNotNull([ + this.auth = Boolean.valueOf(firstNotNull([ execution.getVariable('smtpAuth'), ENV['SMTP_AUTH'], true @@ -55,14 +56,18 @@ class MailSender implements AutoCloseable { this.props = System.getProperties() this.props.put('mail.smtp.host', host) this.props.put('mail.smtp.port', port) - this.props.put('mail.smtp.user', user) - this.props.put('mail.smtp.password', password) this.props.put('mail.smtp.auth', auth) this.props.put('mail.mime.encodefilename', true) + if (this.auth) { + this.props.put('mail.smtp.user', user) + this.props.put('mail.smtp.password', password) + } + if (tls) { this.props.put('mail.smtp.starttls.enable', tls.toString()) // DO NOT REMOVE toString() here !!! } + if (ssl) { this.props.put('mail.smtp.ssl.trust', ssl) } else if (tls) { @@ -79,16 +84,21 @@ class MailSender implements AutoCloseable { if (isEmpty(this.host)) { throw new Exception("Empty host name!") } + if (isEmpty(this.port)) { throw new Exception("Empty port number!") } - if (isEmpty(this.user)) { - throw new Exception("Empty user name!") - } - if (isEmpty(this.password)) { - throw new Exception("Empty password!") + + if (this.auth) { + if (isEmpty(this.user)) { + throw new Exception("Empty user name!") + } + if (isEmpty(this.password)) { + throw new Exception("Empty password!") + } } - this.transport.connect(this.host, this.port, this.user, this.password) + + this.transport.connect() } return this }