Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCX-47 Fix MailSender usage without auth #42

Merged
merged 1 commit into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,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