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

Add option for mailer to override mail headers #27860

Merged
merged 26 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1578,6 +1578,9 @@ LEVEL = Info
;; Prefix displayed before subject in mail
;SUBJECT_PREFIX =
;;
;; Set the Return-Path header where bounced e-mails will be sent to.
;RETURN_PATH =
;;
;; Mail server protocol. One of "smtp", "smtps", "smtp+starttls", "smtp+unix", "sendmail", "dummy".
;; - 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.
Expand Down
1 change: 1 addition & 0 deletions docs/content/administration/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,7 @@ and
- `ENABLE_HELO`: **true**: Enable HELO operation.
- `HELO_HOSTNAME`: **(retrieved from system)**: HELO hostname.
- `FROM`: **_empty_**: Mail from address, RFC 5322. This can be just an email address, or the "Name" \<email@example.com\> format.
- `RETURN_PATH`: **_empty_**: Set the Return-Path header, to let mail clients reply to a different mail as it was send from. See [RFC 4021](https://www.rfc-editor.org/rfc/rfc4021#page-17) for more details.
silverwind marked this conversation as resolved.
Show resolved Hide resolved
silverwind marked this conversation as resolved.
Show resolved Hide resolved
- `ENVELOPE_FROM`: **_empty_**: Address set as the From address on the SMTP mail envelope. Set to `<>` to send an empty address.
- `SUBJECT_PREFIX`: **_empty_**: Prefix to be placed before e-mail subject lines.
- `SENDMAIL_PATH`: **sendmail**: The location of sendmail on the operating system (can be command or full path).
Expand Down
1 change: 1 addition & 0 deletions modules/setting/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Mailer struct {
FromEmail string `ini:"-"`
SendAsPlainText bool `ini:"SEND_AS_PLAIN_TEXT"`
SubjectPrefix string `ini:"SUBJECT_PREFIX"`
ReturnPath string `ini:"RETURN_PATH"`

// SMTP sender
Protocol string `ini:"PROTOCOL"`
Expand Down
5 changes: 4 additions & 1 deletion services/mailer/mailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,14 @@ func (m *Message) ToMessage() *gomail.Message {
msg.SetHeader(header, m.Headers[header]...)
}

if len(setting.MailService.SubjectPrefix) > 0 {
if setting.MailService.SubjectPrefix != "" {
msg.SetHeader("Subject", setting.MailService.SubjectPrefix+" "+m.Subject)
} else {
msg.SetHeader("Subject", m.Subject)
}
if setting.MailService.ReturnPath != "" {
msg.SetHeader("Return-Path", setting.MailService.ReturnPath)
}
msg.SetDateHeader("Date", m.Date)
msg.SetHeader("X-Auto-Response-Suppress", "All")

Expand Down
Loading