diff options
author | zeripath <art27@cantab.net> | 2019-04-17 05:56:40 +0100 |
---|---|---|
committer | techknowlogick <matti@mdranta.net> | 2019-04-17 00:56:40 -0400 |
commit | 827ab6b75a70a3cd90033a4d49bb44c635dd3310 (patch) | |
tree | 4eeb03f67d96288dddedbca0215759c622e5b5b1 | |
parent | 84fd24246cd5565b9654bf752b9919df03e69271 (diff) | |
download | gitea-827ab6b75a70a3cd90033a4d49bb44c635dd3310.tar.gz gitea-827ab6b75a70a3cd90033a4d49bb44c635dd3310.zip |
Add SUBJECT_PREFIX mailer config option (#6605)
* Add SUBJECT_PREFIX mailer config option
* Add space between subject prefix and subject (Change from Gogs)
Signed-off-by: Andrew Thornton <art27@cantab.net>
-rw-r--r-- | custom/conf/app.ini.sample | 4 | ||||
-rw-r--r-- | docs/content/doc/advanced/config-cheat-sheet.en-us.md | 5 | ||||
-rw-r--r-- | modules/mailer/mailer.go | 6 | ||||
-rw-r--r-- | modules/setting/mailer.go | 2 |
4 files changed, 12 insertions, 5 deletions
diff --git a/custom/conf/app.ini.sample b/custom/conf/app.ini.sample index 6dee39ed83..4b846d3aff 100644 --- a/custom/conf/app.ini.sample +++ b/custom/conf/app.ini.sample @@ -411,8 +411,8 @@ PAGING_NUM = 10 ENABLED = false ; Buffer length of channel, keep it as it is if you don't know what it is. SEND_BUFFER_LEN = 100 -; Name displayed in mail title -SUBJECT = %(APP_NAME)s +; Prefix displayed before subject in mail +SUBJECT_PREFIX = ; Mail server ; Gmail: smtp.gmail.com:587 ; QQ: smtp.qq.com:465 diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index 1e97f93e13..8ae89ef4de 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -241,14 +241,15 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`. - `PASSWD`: **\<empty\>**: Password of mailing user. Use \`your password\` for quoting if you use special characters in the password. - `SKIP_VERIFY`: **\<empty\>**: Do not verify the self-signed certificates. - **Note:** Gitea only supports SMTP with STARTTLS. +- `SUBJECT_PREFIX`: **\<empty\>**: Prefix to be placed before e-mail subject lines. - `MAILER_TYPE`: **smtp**: \[smtp, sendmail, dummy\] - **smtp** Use SMTP to send mail - **sendmail** Use the operating system's `sendmail` command instead of SMTP. This is common on linux systems. - **dummy** Send email messages to the log as a testing phase. - Note that enabling sendmail will ignore all other `mailer` settings except `ENABLED`, - `FROM` and `SENDMAIL_PATH`. - - Enabling dummy will ignore all settings except `ENABLED` and `FROM`. + `FROM`, `SUBJECT_PREFIX` and `SENDMAIL_PATH`. + - Enabling dummy will ignore all settings except `ENABLED`, `SUBJECT_PREFIX` and `FROM`. - `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be command or full path). - ``IS_TLS_ENABLED`` : **false** : Decide if SMTP connections should use TLS. diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index 84da0d4c17..411d6eafd8 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -38,7 +38,11 @@ func NewMessageFrom(to []string, fromDisplayName, fromAddress, subject, body str msg := gomail.NewMessage() msg.SetAddressHeader("From", fromAddress, fromDisplayName) msg.SetHeader("To", to...) - msg.SetHeader("Subject", subject) + if len(setting.MailService.SubjectPrefix) > 0 { + msg.SetHeader("Subject", setting.MailService.SubjectPrefix+" "+subject) + } else { + msg.SetHeader("Subject", subject) + } msg.SetDateHeader("Date", time.Now()) msg.SetHeader("X-Auto-Response-Suppress", "All") diff --git a/modules/setting/mailer.go b/modules/setting/mailer.go index e627aef017..3101ed5452 100644 --- a/modules/setting/mailer.go +++ b/modules/setting/mailer.go @@ -21,6 +21,7 @@ type Mailer struct { FromEmail string SendAsPlainText bool MailerType string + SubjectPrefix string // SMTP sender Host string @@ -65,6 +66,7 @@ func newMailService() { CertFile: sec.Key("CERT_FILE").String(), KeyFile: sec.Key("KEY_FILE").String(), IsTLSEnabled: sec.Key("IS_TLS_ENABLED").MustBool(), + SubjectPrefix: sec.Key("SUBJECT_PREFIX").MustString(""), SendmailPath: sec.Key("SENDMAIL_PATH").MustString("sendmail"), } |