Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send mails as HTML as default. Setting for send as plain text. #1648

Merged
merged 4 commits into from
Jun 7, 2017

Conversation

cez81
Copy link
Contributor

@cez81 cez81 commented Apr 30, 2017

As the default mail templates are all HTML and look rather crappy if sent as plain text I think the default should be to send as HTML. HTML is added as mime/alternative so it's still possible to view as plain text.

I have added a new setting, SEND_AS_PLAIN_TEXT, to send as plain text as default instead. Old setting, ENABLE_HTML_ALTERNATIVE, is removed.

Fixes #1342

@strk
Copy link
Member

strk commented May 1, 2017

I actually think mails should be sent as text by default. The fact that the text looks crappy is the bug to fix. I think it depends on mail templates being HTML. They should be turned to text.

@tboerger tboerger added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label May 1, 2017
@cez81
Copy link
Contributor Author

cez81 commented May 2, 2017

I think many users like nicer e-mails. Even if HTML is default, it's sent as multipart and if you don't like then disable it.

@lafriks
Copy link
Member

lafriks commented May 8, 2017

I vote for multipart as default as that is the same github/gitlab is doing

@lunny lunny added this to the 1.2.0 milestone May 9, 2017
@lunny lunny added the type/enhancement An improvement of existing functionality label May 9, 2017
Copy link
Member

@bkcsoft bkcsoft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All in all, There should only be 2 outcomes of NewMessageFrom:

  1. send text/plain
  2. send text/plain and text/html

We should never ever only send text/html...

@@ -1250,9 +1250,9 @@ func newMailService() {
}

MailService = &Mailer{
QueueLength: sec.Key("SEND_BUFFER_LEN").MustInt(100),
Name: sec.Key("NAME").MustString(AppName),
EnableHTMLAlternative: sec.Key("ENABLE_HTML_ALTERNATIVE").MustBool(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove old configs, deprecate them...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added warning

body, err := html2text.FromString(htmlBody)
var plainBody string
var err error
if strings.Contains(body[:100], "<html>") {
Copy link
Member

@bkcsoft bkcsoft May 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we checking this? What if the body starts with <body> (as is customary for templates) or <div>?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this stage it should be a complete HTML file. Anyway I removed it but still check for HTML when sending as plain to generate warning should there be a in the body.

@@ -1269,6 +1269,10 @@ func newMailService() {
}
MailService.From = sec.Key("FROM").MustString(MailService.User)

if sec.HasKey("ENABLE_HTML_ALTERNATIVE") {
log.Warn("ENABLE_HTML_ALTERNATIVE is deprecated, use SEND_AS_PLAIN_TEXT")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to use if SEND_AS_PLAIN_TEXT isn't being set :/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it 👍

@lunny
Copy link
Member

lunny commented May 25, 2017

LGTM

@tboerger tboerger added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels May 25, 2017
msg.SetBody("text/plain", body)
if setting.MailService.EnableHTMLAlternative {
msg.AddAlternative("text/html", htmlBody)
plainBody, _ := html2text.FromString(body)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we ignore the error?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch :)

if err != nil || setting.MailService.SendAsPlainText {

should do the trick :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why I did that, but I have changed it now :)

@ethantkoenig
Copy link
Member

LGTM

@tboerger tboerger added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Jun 6, 2017
@lunny lunny merged commit d9a8eff into go-gitea:master Jun 7, 2017
@cez81 cez81 deleted the html_email branch June 7, 2017 08:37
r0l1 added a commit to r0l1/gitea that referenced this pull request Jun 7, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTML emails are sent as text/plain
7 participants