diff options
author | Unknwon <u@gogs.io> | 2016-05-30 01:32:01 -0700 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2016-05-30 01:32:01 -0700 |
commit | 8df3ba96f3bc26ba5a3d8ca97c381a88aa9a362b (patch) | |
tree | 21d8abe027db92b7bb963fb5055592904912fd14 /modules/mailer | |
parent | d35a1c30f45d11d2e38ac848eb70c89f9a3cc524 (diff) | |
download | gitea-8df3ba96f3bc26ba5a3d8ca97c381a88aa9a362b.tar.gz gitea-8df3ba96f3bc26ba5a3d8ca97c381a88aa9a362b.zip |
#2954 use text/plain as default email content format
Diffstat (limited to 'modules/mailer')
-rw-r--r-- | modules/mailer/mailer.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index b43df4de47..6a979969e4 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -14,11 +14,11 @@ import ( "strings" "time" + "github.com/jaytaylor/html2text" "gopkg.in/gomail.v2" "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/setting" - "github.com/jaytaylor/html2text" ) type Message struct { @@ -27,20 +27,24 @@ type Message struct { } // NewMessageFrom creates new mail message object with custom From header. -func NewMessageFrom(to []string, from, subject, htmlbody string) *Message { +func NewMessageFrom(to []string, from, subject, htmlBody string) *Message { msg := gomail.NewMessage() msg.SetHeader("From", from) msg.SetHeader("To", to...) msg.SetHeader("Subject", subject) msg.SetDateHeader("Date", time.Now()) - body, err := html2text.FromString(htmlbody) + + body, err := html2text.FromString(htmlBody) if err != nil { - // TODO: report error ? - msg.SetBody("text/html", htmlbody) + log.Error(4, "html2text.FromString: %v", err) + msg.SetBody("text/html", htmlBody) + msg.AddAlternative("text/html", htmlBody) } else { msg.SetBody("text/plain", body) - // TODO: avoid this (use a configuration switch?) - msg.AddAlternative("text/html", htmlbody) + } + + if setting.MailService.EnableHTMLAlternative { + msg.AddAlternative("text/html", htmlBody) } return &Message{ |