mirror of
https://github.com/go-gitea/gitea
synced 2025-07-19 16:58:37 +00:00
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>
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
Reference in New Issue
Block a user