Browse Source

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>
tags/v1.9.0-rc1
zeripath techknowlogick 6 years ago
parent
commit
6a89cea472
3 changed files with 10 additions and 3 deletions
  1. +3
    -2
      docs/content/doc/advanced/config-cheat-sheet.en-us.md
  2. +5
    -1
      modules/mailer/mailer.go
  3. +2
    -0
      modules/setting/mailer.go

+ 3
- 2
docs/content/doc/advanced/config-cheat-sheet.en-us.md View File

@@ -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. - `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. - `SKIP_VERIFY`: **\<empty\>**: Do not verify the self-signed certificates.
- **Note:** Gitea only supports SMTP with STARTTLS. - **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\] - `MAILER_TYPE`: **smtp**: \[smtp, sendmail, dummy\]
- **smtp** Use SMTP to send mail - **smtp** Use SMTP to send mail
- **sendmail** Use the operating system's `sendmail` command instead of SMTP. - **sendmail** Use the operating system's `sendmail` command instead of SMTP.
This is common on linux systems. This is common on linux systems.
- **dummy** Send email messages to the log as a testing phase. - **dummy** Send email messages to the log as a testing phase.
- Note that enabling sendmail will ignore all other `mailer` settings except `ENABLED`, - 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 - `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be
command or full path). command or full path).
- ``IS_TLS_ENABLED`` : **false** : Decide if SMTP connections should use TLS. - ``IS_TLS_ENABLED`` : **false** : Decide if SMTP connections should use TLS.


+ 5
- 1
modules/mailer/mailer.go View File

@@ -38,7 +38,11 @@ func NewMessageFrom(to []string, fromDisplayName, fromAddress, subject, body str
msg := gomail.NewMessage() msg := gomail.NewMessage()
msg.SetAddressHeader("From", fromAddress, fromDisplayName) msg.SetAddressHeader("From", fromAddress, fromDisplayName)
msg.SetHeader("To", to...) 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.SetDateHeader("Date", time.Now())
msg.SetHeader("X-Auto-Response-Suppress", "All") msg.SetHeader("X-Auto-Response-Suppress", "All")




+ 2
- 0
modules/setting/mailer.go View File

@@ -21,6 +21,7 @@ type Mailer struct {
FromEmail string FromEmail string
SendAsPlainText bool SendAsPlainText bool
MailerType string MailerType string
SubjectPrefix string


// SMTP sender // SMTP sender
Host string Host string
@@ -65,6 +66,7 @@ func newMailService() {
CertFile: sec.Key("CERT_FILE").String(), CertFile: sec.Key("CERT_FILE").String(),
KeyFile: sec.Key("KEY_FILE").String(), KeyFile: sec.Key("KEY_FILE").String(),
IsTLSEnabled: sec.Key("IS_TLS_ENABLED").MustBool(), IsTLSEnabled: sec.Key("IS_TLS_ENABLED").MustBool(),
SubjectPrefix: sec.Key("SUBJECT_PREFIX").MustString(""),


SendmailPath: sec.Key("SENDMAIL_PATH").MustString("sendmail"), SendmailPath: sec.Key("SENDMAIL_PATH").MustString("sendmail"),
} }


Loading…
Cancel
Save