Skip to content

Commit 827ab6b

Browse files
zeripathtechknowlogick
authored andcommitted
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 <[email protected]>
1 parent 84fd242 commit 827ab6b

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

custom/conf/app.ini.sample

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,8 @@ PAGING_NUM = 10
411411
ENABLED = false
412412
; Buffer length of channel, keep it as it is if you don't know what it is.
413413
SEND_BUFFER_LEN = 100
414-
; Name displayed in mail title
415-
SUBJECT = %(APP_NAME)s
414+
; Prefix displayed before subject in mail
415+
SUBJECT_PREFIX =
416416
; Mail server
417417
; Gmail: smtp.gmail.com:587
418418
; QQ: smtp.qq.com:465

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,14 +241,15 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
241241
- `PASSWD`: **\<empty\>**: Password of mailing user. Use \`your password\` for quoting if you use special characters in the password.
242242
- `SKIP_VERIFY`: **\<empty\>**: Do not verify the self-signed certificates.
243243
- **Note:** Gitea only supports SMTP with STARTTLS.
244+
- `SUBJECT_PREFIX`: **\<empty\>**: Prefix to be placed before e-mail subject lines.
244245
- `MAILER_TYPE`: **smtp**: \[smtp, sendmail, dummy\]
245246
- **smtp** Use SMTP to send mail
246247
- **sendmail** Use the operating system's `sendmail` command instead of SMTP.
247248
This is common on linux systems.
248249
- **dummy** Send email messages to the log as a testing phase.
249250
- Note that enabling sendmail will ignore all other `mailer` settings except `ENABLED`,
250-
`FROM` and `SENDMAIL_PATH`.
251-
- Enabling dummy will ignore all settings except `ENABLED` and `FROM`.
251+
`FROM`, `SUBJECT_PREFIX` and `SENDMAIL_PATH`.
252+
- Enabling dummy will ignore all settings except `ENABLED`, `SUBJECT_PREFIX` and `FROM`.
252253
- `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be
253254
command or full path).
254255
- ``IS_TLS_ENABLED`` : **false** : Decide if SMTP connections should use TLS.

modules/mailer/mailer.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ func NewMessageFrom(to []string, fromDisplayName, fromAddress, subject, body str
3838
msg := gomail.NewMessage()
3939
msg.SetAddressHeader("From", fromAddress, fromDisplayName)
4040
msg.SetHeader("To", to...)
41-
msg.SetHeader("Subject", subject)
41+
if len(setting.MailService.SubjectPrefix) > 0 {
42+
msg.SetHeader("Subject", setting.MailService.SubjectPrefix+" "+subject)
43+
} else {
44+
msg.SetHeader("Subject", subject)
45+
}
4246
msg.SetDateHeader("Date", time.Now())
4347
msg.SetHeader("X-Auto-Response-Suppress", "All")
4448

modules/setting/mailer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type Mailer struct {
2121
FromEmail string
2222
SendAsPlainText bool
2323
MailerType string
24+
SubjectPrefix string
2425

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

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

0 commit comments

Comments
 (0)