From 3b62f06f1b8077b85b8038cc59aa1731a2461079 Mon Sep 17 00:00:00 2001 From: ruhnet Date: Sat, 29 Oct 2022 16:05:07 -0400 Subject: [PATCH] Added check for explicit empty values in mailer config. If empty values are provided for user/password, SMTP authentication will not be used when sending mails. This is useful when the mail server being utilized is localhost (or on a trusted network) and doesn't use authentication. --- CONTRIBUTORS.md | 1 + engine/action.go | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 3d5d3cba3..ea9542041 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -85,6 +85,7 @@ information, please see the [`CONTRIBUTING.md`](CONTRIBUTING.md) file. | @nickvsnetworking | Nick Jones | | @Eda91 | Edlira Eltari | | @gezimbll | Gezim Blliku| +| @ruhnet | Ruel Tmeizeh | diff --git a/engine/action.go b/engine/action.go index 56a966871..3b5ded3dc 100644 --- a/engine/action.go +++ b/engine/action.go @@ -402,7 +402,10 @@ func mailAsync(ub *Account, a *Action, acs Actions, _ *FilterS, extraData interf } message = []byte(fmt.Sprintf("To: %s\r\nSubject: [CGR Notification] Threshold hit on Balance: %s\r\n\r\nTime: \r\n\t%s\r\n\r\nBalance:\r\n\t%s\r\n\r\nYours faithfully,\r\nCGR Balance Monitor\r\n", toAddrStr, ub.ID, time.Now(), balJsn)) } - auth := smtp.PlainAuth("", cgrCfg.MailerCfg().MailerAuthUser, cgrCfg.MailerCfg().MailerAuthPass, strings.Split(cgrCfg.MailerCfg().MailerServer, ":")[0]) // We only need host part, so ignore port + var auth smtp.Auth + if len(cgrCfg.MailerCfg().MailerAuthUser) > 0 || len(cgrCfg.MailerCfg().MailerAuthPass) > 0 { //use auth if user/pass not empty in config + auth = smtp.PlainAuth("", cgrCfg.MailerCfg().MailerAuthUser, cgrCfg.MailerCfg().MailerAuthPass, strings.Split(cgrCfg.MailerCfg().MailerServer, ":")[0]) // We only need host part, so ignore port + } go func() { for i := 0; i < 5; i++ { // Loop so we can increase the success rate on best effort if err := smtp.SendMail(cgrCfg.MailerCfg().MailerServer, auth, cgrCfg.MailerCfg().MailerFromAddr, toAddrs, message); err == nil {