Skip to content

Commit

Permalink
HCX-47 Fix MailSender usage without auth (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfinus authored and dolfinus committed Feb 28, 2020
1 parent d93832f commit dfa5f75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
-------------------
Expand Down
28 changes: 19 additions & 9 deletions src/org/camunda/latera/bss/connectors/MailSender.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand All @@ -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
}
Expand Down

0 comments on commit dfa5f75

Please sign in to comment.