Skip to content

Commit 20edfa5

Browse files
committed
Remove USE_DIFFERENT_ENVELOPE_FROM option - instead determine whether to use it from
the value Signed-off-by: Andrew Thornton <art27@cantab.net>
1 parent 641aaa1 commit 20edfa5

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

custom/conf/app.example.ini

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,8 +1450,7 @@ PATH =
14501450
;; Mail from address, RFC 5322. This can be just an email address, or the `"Name" <email@example.com>` format
14511451
;FROM =
14521452
;;
1453-
;; Sometimes it is helpful to use a different address on the envelope. Set USE_DIFFERENT_ENVELOPE_FROM to true to use ENVELOPE_FROM as the from on the envelope
1454-
;USE_DIFFERENT_ENVELOPE_FROM=false
1453+
;; Sometimes it is helpful to use a different address on the envelope. Set this to use ENVELOPE_FROM as the from on the envelope. Set to `<>` to send an empty address.
14551454
;ENVELOPE_FROM =
14561455
;;
14571456
;; Mailer user name and password

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,7 @@ Define allowed algorithms and their minimum key length (use -1 to disable a type
598598
- Otherwise if `IS_TLS_ENABLED=false` and the server supports `STARTTLS` this will be used. Thus if `STARTTLS` is preferred you should set `IS_TLS_ENABLED=false`.
599599
- `FROM`: **\<empty\>**: Mail from address, RFC 5322. This can be just an email address, or
600600
the "Name" \<email@example.com\> format.
601-
- `USE_DIFFERENT_ENVELOPE_FROM`: **false**: Set to **true** to use the value of `ENVELOPE_FROM` as the From address on the SMTP mail envelope.
602-
- `ENVELOPE_FROM`: **\<empty\>**: Address set as the From address on the SMTP mail envelope if `USE_DIFFERENT_ENVELOPE_FROM` is set to true.
601+
- `ENVELOPE_FROM`: **\<empty\>**: Address set as the From address on the SMTP mail envelope. Set to `<>` to send an empty address.
603602
- `USER`: **\<empty\>**: Username of mailing user (usually the sender's e-mail address).
604603
- `PASSWD`: **\<empty\>**: Password of mailing user. Use \`your password\` for quoting if you use special characters in the password.
605604
- Please note: authentication is only supported when the SMTP server communication is encrypted with TLS (this can be via `STARTTLS`) or `HOST=localhost`. See [Email Setup]({{< relref "doc/usage/email-setup.en-us.md" >}}) for more information.

modules/setting/mailer.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ import (
1616
// Mailer represents mail service.
1717
type Mailer struct {
1818
// Mailer
19-
Name string
20-
From string
21-
EnvelopeFrom string
22-
UseDifferentEnvelopeFrom bool
23-
FromName string
24-
FromEmail string
25-
SendAsPlainText bool
26-
MailerType string
27-
SubjectPrefix string
19+
Name string
20+
From string
21+
EnvelopeFrom string
22+
OverrideEnvelopeFrom bool `ini:"-"`
23+
FromName string
24+
FromEmail string
25+
SendAsPlainText bool
26+
MailerType string
27+
SubjectPrefix string
2828

2929
// SMTP sender
3030
Host string
@@ -75,7 +75,6 @@ func newMailService() {
7575
SendmailTimeout: sec.Key("SENDMAIL_TIMEOUT").MustDuration(5 * time.Minute),
7676
}
7777
MailService.From = sec.Key("FROM").MustString(MailService.User)
78-
MailService.UseDifferentEnvelopeFrom = sec.Key("USE_DIFFERENT_ENVELOPE_FROM").MustBool()
7978
MailService.EnvelopeFrom = sec.Key("ENVELOPE_FROM").MustString("")
8079

8180
if sec.HasKey("ENABLE_HTML_ALTERNATIVE") {
@@ -97,6 +96,21 @@ func newMailService() {
9796
MailService.FromName = parsed.Name
9897
MailService.FromEmail = parsed.Address
9998

99+
switch MailService.EnvelopeFrom {
100+
case "":
101+
MailService.OverrideEnvelopeFrom = false
102+
case "<>":
103+
MailService.EnvelopeFrom = ""
104+
MailService.OverrideEnvelopeFrom = true
105+
default:
106+
parsed, err = mail.ParseAddress(MailService.EnvelopeFrom)
107+
if err != nil {
108+
log.Fatal("Invalid mailer.ENVELOPE_FROM (%s): %v", MailService.EnvelopeFrom, err)
109+
}
110+
MailService.OverrideEnvelopeFrom = true
111+
MailService.EnvelopeFrom = parsed.String()
112+
}
113+
100114
if MailService.MailerType == "" {
101115
MailService.MailerType = "smtp"
102116
}

services/mailer/mailer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (s *smtpSender) Send(from string, to []string, msg io.WriterTo) error {
210210
}
211211
}
212212

213-
if opts.UseDifferentEnvelopeFrom {
213+
if opts.OverrideEnvelopeFrom {
214214
if err = client.Mail(opts.EnvelopeFrom); err != nil {
215215
return fmt.Errorf("Mail: %v", err)
216216
}
@@ -249,7 +249,7 @@ func (s *sendmailSender) Send(from string, to []string, msg io.WriterTo) error {
249249
var waitError error
250250

251251
envelopeFrom := from
252-
if setting.MailService.UseDifferentEnvelopeFrom {
252+
if setting.MailService.OverrideEnvelopeFrom {
253253
envelopeFrom = setting.MailService.EnvelopeFrom
254254
}
255255

0 commit comments

Comments
 (0)