52d153da by astaxie

Merge pull request #710 from francoishill/patch-8

Update smtp.go (develop branch)
2 parents 91ee42ce 6ce55e88
...@@ -54,6 +54,18 @@ func (s *SmtpWriter) Init(jsonconfig string) error { ...@@ -54,6 +54,18 @@ func (s *SmtpWriter) Init(jsonconfig string) error {
54 return nil 54 return nil
55 } 55 }
56 56
57 func (s *SmtpWriter) GetSmtpAuth(host string) smtp.Auth {
58 if len(strings.Trim(s.Username, " ")) == 0 && len(strings.Trim(s.Password, " ")) == 0 {
59 return nil
60 }
61 return smtp.PlainAuth(
62 "",
63 s.Username,
64 s.Password,
65 host,
66 )
67 }
68
57 // write message in smtp writer. 69 // write message in smtp writer.
58 // it will send an email with subject and only this message. 70 // it will send an email with subject and only this message.
59 func (s *SmtpWriter) WriteMsg(msg string, level int) error { 71 func (s *SmtpWriter) WriteMsg(msg string, level int) error {
...@@ -64,12 +76,8 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error { ...@@ -64,12 +76,8 @@ func (s *SmtpWriter) WriteMsg(msg string, level int) error {
64 hp := strings.Split(s.Host, ":") 76 hp := strings.Split(s.Host, ":")
65 77
66 // Set up authentication information. 78 // Set up authentication information.
67 auth := smtp.PlainAuth( 79 auth := s.GetSmtpAuth(hp[0])
68 "", 80
69 s.Username,
70 s.Password,
71 hp[0],
72 )
73 // Connect to the server, authenticate, set the sender and recipient, 81 // Connect to the server, authenticate, set the sender and recipient,
74 // and send the email all in one step. 82 // and send the email all in one step.
75 content_type := "Content-Type: text/plain" + "; charset=UTF-8" 83 content_type := "Content-Type: text/plain" + "; charset=UTF-8"
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!