diff options
author | zeripath <art27@cantab.net> | 2021-11-19 15:35:20 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-19 23:35:20 +0800 |
commit | 38347aa16f7cfb32bb984ade4518bd311d0aff12 (patch) | |
tree | b1566f8cb2a481162b799e86308eb522d51f33e1 /modules | |
parent | d4e281bc02908f5e1dda3dc4d340e2898048faef (diff) | |
download | gitea-38347aa16f7cfb32bb984ade4518bd311d0aff12.tar.gz gitea-38347aa16f7cfb32bb984ade4518bd311d0aff12.zip |
Add settings to allow different SMTP envelope from address (#17479)
* Add settings to allow different SMTP envelope from address
Sometimes it may be advisable to hide or alias the from address on an SMTP mail
envelope. This PR adds two new options to the mailer to allow setting of an overriding
from address.
Fix #17477
Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/setting/mailer.go | 32 |
1 files changed, 25 insertions, 7 deletions
diff --git a/modules/setting/mailer.go b/modules/setting/mailer.go index d2fac440ac..1bcd63a914 100644 --- a/modules/setting/mailer.go +++ b/modules/setting/mailer.go @@ -16,13 +16,15 @@ import ( // Mailer represents mail service. type Mailer struct { // Mailer - Name string - From string - FromName string - FromEmail string - SendAsPlainText bool - MailerType string - SubjectPrefix string + Name string + From string + EnvelopeFrom string + OverrideEnvelopeFrom bool `ini:"-"` + FromName string + FromEmail string + SendAsPlainText bool + MailerType string + SubjectPrefix string // SMTP sender Host string @@ -73,6 +75,7 @@ func newMailService() { SendmailTimeout: sec.Key("SENDMAIL_TIMEOUT").MustDuration(5 * time.Minute), } MailService.From = sec.Key("FROM").MustString(MailService.User) + MailService.EnvelopeFrom = sec.Key("ENVELOPE_FROM").MustString("") if sec.HasKey("ENABLE_HTML_ALTERNATIVE") { log.Warn("ENABLE_HTML_ALTERNATIVE is deprecated, use SEND_AS_PLAIN_TEXT") @@ -93,6 +96,21 @@ func newMailService() { MailService.FromName = parsed.Name MailService.FromEmail = parsed.Address + switch MailService.EnvelopeFrom { + case "": + MailService.OverrideEnvelopeFrom = false + case "<>": + MailService.EnvelopeFrom = "" + MailService.OverrideEnvelopeFrom = true + default: + parsed, err = mail.ParseAddress(MailService.EnvelopeFrom) + if err != nil { + log.Fatal("Invalid mailer.ENVELOPE_FROM (%s): %v", MailService.EnvelopeFrom, err) + } + MailService.OverrideEnvelopeFrom = true + MailService.EnvelopeFrom = parsed.Address + } + if MailService.MailerType == "" { MailService.MailerType = "smtp" } |