From f5a7199254ee2e26a72a627f29a8952956e32aa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ajdi=C5=A1ek?= Date: Fri, 22 Apr 2016 10:41:44 +0200 Subject: [PATCH] Support email notification without SMTP auth. Even if .drone.yml does not specify username and password, gomail.NewPlainDialer is still populated with them - albeit empty - which means they are still being sent to SMTP server. In case of Google's smtp-relay.gmail.com this will result in an error, even if CI's server IP address is added to exclusion list allowing it to skip auth entirely. This commit constructs gomail.Dialer without username and password if there was no username found in .drone.yml. * Constructs gomail.Dialer without username when no username in .drone.yml * Replaces gomail.NewPlainDialer with gomail.NewDialer --- sender.go | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/sender.go b/sender.go index 92f2113..8440df6 100644 --- a/sender.go +++ b/sender.go @@ -103,12 +103,21 @@ func send(subject, plainBody, htmlBody string, c *Context) error { htmlBody, ) - d := gomail.NewPlainDialer( - c.Vargs.Host, - c.Vargs.Port, - c.Vargs.Username, - c.Vargs.Password, - ) + var d *gomail.Dialer + if c.Vargs.Username == "" { + d = &gomail.Dialer{ + Host: c.Vargs.Host, + Port: c.Vargs.Port, + SSL: c.Vargs.Port == 465, + } + } else { + d = gomail.NewDialer( + c.Vargs.Host, + c.Vargs.Port, + c.Vargs.Username, + c.Vargs.Password, + ) + } if c.Vargs.SkipVerify { d.TLSConfig = &tls.Config{