From 6ce55e8884d0a2ed6f7f7f53414b6317eb3c7394 Mon Sep 17 00:00:00 2001 From: Francois Date: Tue, 22 Jul 2014 07:21:47 +0200 Subject: [PATCH] Update smtp.go (develop branch) For mail servers that do not require Authentication we must pass NIL for the SendMail parameter 2 (the auth parameter). Otherwise it fails to send the mail. --- logs/smtp.go | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/logs/smtp.go b/logs/smtp.go index d492a61a..fa5dc78e 100644 --- a/logs/smtp.go +++ b/logs/smtp.go @@ -54,6 +54,18 @@ func (s *SmtpWriter) Init(jsonconfig string) error { return nil } +func (s *SmtpWriter) GetSmtpAuth(host string) smtp.Auth { + if len(strings.Trim(s.Username, " ")) == 0 && len(strings.Trim(s.Password, " ")) == 0 { + return nil + } + return smtp.PlainAuth( + "", + s.Username, + s.Password, + host, + ) +} + // write message in smtp writer. // it will send an email with subject and only this message. func (s *SmtpWriter) WriteMsg(msg string, level int) error { @@ -64,12 +76,8 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { hp := strings.Split(s.Host, ":") // Set up authentication information. - auth := smtp.PlainAuth( - "", - s.Username, - s.Password, - hp[0], - ) + auth := s.GetSmtpAuth(hp[0]) + // Connect to the server, authenticate, set the sender and recipient, // and send the email all in one step. content_type := "Content-Type: text/plain" + "; charset=UTF-8"