mailer: make text/html as default format
Change config option from '[mailer] ENABLE_HTML_ALTERNATIVE' to '[mailer] USE_PLAIN_TEXT'master
parent
a47553b7aa
commit
c7a8051a71
|
@ -13,6 +13,7 @@ The issue will be closed without any reasons if it does not satisfy any of follo
|
||||||
- Database (use `[x]`):
|
- Database (use `[x]`):
|
||||||
- [ ] PostgreSQL
|
- [ ] PostgreSQL
|
||||||
- [ ] MySQL
|
- [ ] MySQL
|
||||||
|
- [ ] MSSQL
|
||||||
- [ ] SQLite
|
- [ ] SQLite
|
||||||
- Can you reproduce the bug at https://try.gogs.io:
|
- Can you reproduce the bug at https://try.gogs.io:
|
||||||
- [ ] Yes (provide example URL)
|
- [ ] Yes (provide example URL)
|
||||||
|
|
|
@ -218,8 +218,8 @@ FROM =
|
||||||
; Mailer user name and password
|
; Mailer user name and password
|
||||||
USER =
|
USER =
|
||||||
PASSWD =
|
PASSWD =
|
||||||
; Use text/html as alternative format of content
|
; Use text/plain as format of content
|
||||||
ENABLE_HTML_ALTERNATIVE = false
|
USE_PLAIN_TEXT = false
|
||||||
|
|
||||||
[cache]
|
[cache]
|
||||||
; Either "memory", "redis", or "memcache", default is "memory"
|
; Either "memory", "redis", or "memcache", default is "memory"
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -36,16 +36,18 @@ func NewMessageFrom(to []string, from, subject, htmlBody string) *Message {
|
||||||
msg.SetHeader("Subject", subject)
|
msg.SetHeader("Subject", subject)
|
||||||
msg.SetDateHeader("Date", time.Now())
|
msg.SetDateHeader("Date", time.Now())
|
||||||
|
|
||||||
body, err := html2text.FromString(htmlBody)
|
contentType := "text/html"
|
||||||
if err != nil {
|
body := htmlBody
|
||||||
log.Error(4, "html2text.FromString: %v", err)
|
if setting.MailService.UsePlainText {
|
||||||
msg.SetBody("text/html", htmlBody)
|
plainBody, err := html2text.FromString(htmlBody)
|
||||||
} else {
|
if err != nil {
|
||||||
msg.SetBody("text/plain", body)
|
log.Error(2, "html2text.FromString: %v", err)
|
||||||
if setting.MailService.EnableHTMLAlternative {
|
} else {
|
||||||
msg.AddAlternative("text/html", htmlBody)
|
contentType = "text/plain"
|
||||||
|
body = plainBody
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
msg.SetBody(contentType, body)
|
||||||
|
|
||||||
return &Message{
|
return &Message{
|
||||||
Message: msg,
|
Message: msg,
|
||||||
|
|
|
@ -751,18 +751,18 @@ func newSessionService() {
|
||||||
|
|
||||||
// Mailer represents mail service.
|
// Mailer represents mail service.
|
||||||
type Mailer struct {
|
type Mailer struct {
|
||||||
QueueLength int
|
QueueLength int
|
||||||
Name string
|
Subject string
|
||||||
Host string
|
Host string
|
||||||
From string
|
From string
|
||||||
FromEmail string
|
FromEmail string
|
||||||
User, Passwd string
|
User, Passwd string
|
||||||
DisableHelo bool
|
DisableHelo bool
|
||||||
HeloHostname string
|
HeloHostname string
|
||||||
SkipVerify bool
|
SkipVerify bool
|
||||||
UseCertificate bool
|
UseCertificate bool
|
||||||
CertFile, KeyFile string
|
CertFile, KeyFile string
|
||||||
EnableHTMLAlternative bool
|
UsePlainText bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -777,18 +777,18 @@ func newMailService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
MailService = &Mailer{
|
MailService = &Mailer{
|
||||||
QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
|
QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
|
||||||
Name: sec.Key("NAME").MustString(AppName),
|
Subject: sec.Key("SUBJECT").MustString(AppName),
|
||||||
Host: sec.Key("HOST").String(),
|
Host: sec.Key("HOST").String(),
|
||||||
User: sec.Key("USER").String(),
|
User: sec.Key("USER").String(),
|
||||||
Passwd: sec.Key("PASSWD").String(),
|
Passwd: sec.Key("PASSWD").String(),
|
||||||
DisableHelo: sec.Key("DISABLE_HELO").MustBool(),
|
DisableHelo: sec.Key("DISABLE_HELO").MustBool(),
|
||||||
HeloHostname: sec.Key("HELO_HOSTNAME").String(),
|
HeloHostname: sec.Key("HELO_HOSTNAME").String(),
|
||||||
SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
|
SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
|
||||||
UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
|
UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
|
||||||
CertFile: sec.Key("CERT_FILE").String(),
|
CertFile: sec.Key("CERT_FILE").String(),
|
||||||
KeyFile: sec.Key("KEY_FILE").String(),
|
KeyFile: sec.Key("KEY_FILE").String(),
|
||||||
EnableHTMLAlternative: sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(),
|
UsePlainText: sec.Key("USE_PLAIN_TEXT").MustBool(),
|
||||||
}
|
}
|
||||||
MailService.From = sec.Key("FROM").MustString(MailService.User)
|
MailService.From = sec.Key("FROM").MustString(MailService.User)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue