make smtp-auth optional

This commit is contained in:
Andrew Karpow 2014-02-16 22:36:01 +01:00
parent 4648ca9669
commit d18fc8fc35

View file

@ -122,7 +122,11 @@ func Send(msg *Message) error {
// format the raw email message body
body := fmt.Sprintf(emailTemplate, msg.Sender, msg.To, msg.Subject, msg.Body)
auth := smtp.PlainAuth("", s.SmtpUsername, s.SmtpPassword, s.SmtpServer)
var auth smtp.Auth
if len(s.SmtpUsername) > 0 {
auth = smtp.PlainAuth("", s.SmtpUsername, s.SmtpPassword, s.SmtpServer)
}
addr := fmt.Sprintf("%s:%s", s.SmtpServer, s.SmtpPort)
err = smtp.SendMail(addr, auth, msg.Sender, []string{msg.To}, []byte(body))