diff options
author | 无闻 <u@gogs.io> | 2014-12-21 01:55:28 -0500 |
---|---|---|
committer | 无闻 <u@gogs.io> | 2014-12-21 01:55:28 -0500 |
commit | 030b3d751e3fc55429ed4cbab76d85d610688d0c (patch) | |
tree | a6c0a794b164d32adb93488b5afb5446b44ca5e0 /modules/mailer | |
parent | 79537467da16a6eb877df20f295a447037092903 (diff) | |
parent | c884ecfea18b001ceb9cdbe98c8618a345f460e0 (diff) | |
download | gitea-030b3d751e3fc55429ed4cbab76d85d610688d0c.tar.gz gitea-030b3d751e3fc55429ed4cbab76d85d610688d0c.zip |
Merge pull request #766 from phsmit/correct_from
Correct usage of FROM in email creation
Diffstat (limited to 'modules/mailer')
-rw-r--r-- | modules/mailer/mail.go | 4 | ||||
-rw-r--r-- | modules/mailer/mailer.go | 17 |
2 files changed, 11 insertions, 10 deletions
diff --git a/modules/mailer/mail.go b/modules/mailer/mail.go index 21f33b17e8..ae8ce6531a 100644 --- a/modules/mailer/mail.go +++ b/modules/mailer/mail.go @@ -31,9 +31,7 @@ const ( // Create New mail message use MailFrom and MailUser func NewMailMessageFrom(To []string, from, subject, body string) Message { - msg := NewHtmlMessage(To, from, subject, body) - msg.User = setting.MailService.User - return msg + return NewHtmlMessage(To, from, subject, body) } // Create New mail message use MailFrom and MailUser diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index f17e5c2736..e2d185d82d 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -8,6 +8,7 @@ import ( "crypto/tls" "fmt" "net" + "net/mail" "net/smtp" "strings" @@ -20,7 +21,6 @@ type Message struct { From string Subject string Body string - User string Type string Massive bool Info string @@ -35,8 +35,7 @@ func (m Message) Content() string { } // create mail content - content := "From: \"" + m.From + "\" <" + m.User + - ">\r\nSubject: " + m.Subject + "\r\nContent-Type: " + contentType + "\r\n\r\n" + m.Body + content := "From: " + m.From + "\r\nSubject: " + m.Subject + "\r\nContent-Type: " + contentType + "\r\n\r\n" + m.Body return content } @@ -67,7 +66,7 @@ func processMailQueue() { } // sendMail allows mail with self-signed certificates. -func sendMail(settings *setting.Mailer, from string, recipients []string, msgContent []byte) error { +func sendMail(settings *setting.Mailer, recipients []string, msgContent []byte) error { host, port, err := net.SplitHostPort(settings.Host) if err != nil { return err @@ -122,8 +121,12 @@ func sendMail(settings *setting.Mailer, from string, recipients []string, msgCon } } - if err = client.Mail(from); err != nil { + if fromAddress, err := mail.ParseAddress(settings.From); err != nil { return err + } else { + if err = client.Mail(fromAddress.Address); err != nil { + return err + } } for _, rec := range recipients { @@ -165,7 +168,7 @@ func Send(msg *Message) (int, error) { num := 0 for _, to := range msg.To { body := []byte("To: " + to + "\r\n" + content) - err := sendMail(setting.MailService, msg.From, []string{to}, body) + err := sendMail(setting.MailService, []string{to}, body) if err != nil { return num, err } @@ -176,7 +179,7 @@ func Send(msg *Message) (int, error) { body := []byte("To: " + strings.Join(msg.To, ";") + "\r\n" + content) // send to multiple emails in one message - err := sendMail(setting.MailService, msg.From, msg.To, body) + err := sendMail(setting.MailService, msg.To, body) if err != nil { return 0, err } else { |