Skip to content

Commit c7a8051

Browse files
committed
mailer: make text/html as default format
Change config option from '[mailer] ENABLE_HTML_ALTERNATIVE' to '[mailer] USE_PLAIN_TEXT'
1 parent a47553b commit c7a8051

File tree

5 files changed

+39
-36
lines changed

5 files changed

+39
-36
lines changed

.github/ISSUE_TEMPLATE.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ The issue will be closed without any reasons if it does not satisfy any of follo
1313
- Database (use `[x]`):
1414
- [ ] PostgreSQL
1515
- [ ] MySQL
16+
- [ ] MSSQL
1617
- [ ] SQLite
1718
- Can you reproduce the bug at https://try.gogs.io:
1819
- [ ] Yes (provide example URL)

conf/app.ini

+2-2
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ FROM =
218218
; Mailer user name and password
219219
USER =
220220
PASSWD =
221-
; Use text/html as alternative format of content
222-
ENABLE_HTML_ALTERNATIVE = false
221+
; Use text/plain as format of content
222+
USE_PLAIN_TEXT = false
223223

224224
[cache]
225225
; Either "memory", "redis", or "memcache", default is "memory"

modules/bindata/bindata.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/mailer/mailer.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,18 @@ func NewMessageFrom(to []string, from, subject, htmlBody string) *Message {
3636
msg.SetHeader("Subject", subject)
3737
msg.SetDateHeader("Date", time.Now())
3838

39-
body, err := html2text.FromString(htmlBody)
40-
if err != nil {
41-
log.Error(4, "html2text.FromString: %v", err)
42-
msg.SetBody("text/html", htmlBody)
43-
} else {
44-
msg.SetBody("text/plain", body)
45-
if setting.MailService.EnableHTMLAlternative {
46-
msg.AddAlternative("text/html", htmlBody)
39+
contentType := "text/html"
40+
body := htmlBody
41+
if setting.MailService.UsePlainText {
42+
plainBody, err := html2text.FromString(htmlBody)
43+
if err != nil {
44+
log.Error(2, "html2text.FromString: %v", err)
45+
} else {
46+
contentType = "text/plain"
47+
body = plainBody
4748
}
4849
}
50+
msg.SetBody(contentType, body)
4951

5052
return &Message{
5153
Message: msg,

modules/setting/setting.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -751,18 +751,18 @@ func newSessionService() {
751751

752752
// Mailer represents mail service.
753753
type Mailer struct {
754-
QueueLength int
755-
Name string
756-
Host string
757-
From string
758-
FromEmail string
759-
User, Passwd string
760-
DisableHelo bool
761-
HeloHostname string
762-
SkipVerify bool
763-
UseCertificate bool
764-
CertFile, KeyFile string
765-
EnableHTMLAlternative bool
754+
QueueLength int
755+
Subject string
756+
Host string
757+
From string
758+
FromEmail string
759+
User, Passwd string
760+
DisableHelo bool
761+
HeloHostname string
762+
SkipVerify bool
763+
UseCertificate bool
764+
CertFile, KeyFile string
765+
UsePlainText bool
766766
}
767767

768768
var (
@@ -777,18 +777,18 @@ func newMailService() {
777777
}
778778

779779
MailService = &Mailer{
780-
QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
781-
Name: sec.Key("NAME").MustString(AppName),
782-
Host: sec.Key("HOST").String(),
783-
User: sec.Key("USER").String(),
784-
Passwd: sec.Key("PASSWD").String(),
785-
DisableHelo: sec.Key("DISABLE_HELO").MustBool(),
786-
HeloHostname: sec.Key("HELO_HOSTNAME").String(),
787-
SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
788-
UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
789-
CertFile: sec.Key("CERT_FILE").String(),
790-
KeyFile: sec.Key("KEY_FILE").String(),
791-
EnableHTMLAlternative: sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(),
780+
QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
781+
Subject: sec.Key("SUBJECT").MustString(AppName),
782+
Host: sec.Key("HOST").String(),
783+
User: sec.Key("USER").String(),
784+
Passwd: sec.Key("PASSWD").String(),
785+
DisableHelo: sec.Key("DISABLE_HELO").MustBool(),
786+
HeloHostname: sec.Key("HELO_HOSTNAME").String(),
787+
SkipVerify: sec.Key("SKIP_VERIFY").MustBool(),
788+
UseCertificate: sec.Key("USE_CERTIFICATE").MustBool(),
789+
CertFile: sec.Key("CERT_FILE").String(),
790+
KeyFile: sec.Key("KEY_FILE").String(),
791+
UsePlainText: sec.Key("USE_PLAIN_TEXT").MustBool(),
792792
}
793793
MailService.From = sec.Key("FROM").MustString(MailService.User)
794794

0 commit comments

Comments
 (0)