mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 21:00:57 +00:00
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.
This commit is contained in:
parent
91ee42ceeb
commit
6ce55e8884
20
logs/smtp.go
20
logs/smtp.go
@ -54,6 +54,18 @@ func (s *SmtpWriter) Init(jsonconfig string) error {
|
|||||||
return nil
|
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.
|
// write message in smtp writer.
|
||||||
// it will send an email with subject and only this message.
|
// it will send an email with subject and only this message.
|
||||||
func (s *SmtpWriter) WriteMsg(msg string, level int) error {
|
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, ":")
|
hp := strings.Split(s.Host, ":")
|
||||||
|
|
||||||
// Set up authentication information.
|
// Set up authentication information.
|
||||||
auth := smtp.PlainAuth(
|
auth := s.GetSmtpAuth(hp[0])
|
||||||
"",
|
|
||||||
s.Username,
|
|
||||||
s.Password,
|
|
||||||
hp[0],
|
|
||||||
)
|
|
||||||
// Connect to the server, authenticate, set the sender and recipient,
|
// Connect to the server, authenticate, set the sender and recipient,
|
||||||
// and send the email all in one step.
|
// and send the email all in one step.
|
||||||
content_type := "Content-Type: text/plain" + "; charset=UTF-8"
|
content_type := "Content-Type: text/plain" + "; charset=UTF-8"
|
||||||
|
Loading…
Reference in New Issue
Block a user