feat(mail): derive bare envelope sender from display-name From
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
+13
-1
@@ -46,6 +46,18 @@ func (m OutgoingMessage) Recipients() []string {
|
||||
return out
|
||||
}
|
||||
|
||||
// envelopeFrom returns the bare address for the SMTP envelope sender, stripping
|
||||
// any display name. A display-name From (e.g. "Name <addr>") is a valid header
|
||||
// but an invalid envelope sender, so it must be reduced to the bare address.
|
||||
// Unparseable input is passed through unchanged (preserves prior behaviour for
|
||||
// plain addresses).
|
||||
func envelopeFrom(from string) string {
|
||||
if a, err := gomail.ParseAddress(from); err == nil {
|
||||
return a.Address
|
||||
}
|
||||
return from
|
||||
}
|
||||
|
||||
func addrList(addrs []string) []*gomail.Address {
|
||||
out := make([]*gomail.Address, 0, len(addrs))
|
||||
for _, a := range addrs {
|
||||
@@ -163,7 +175,7 @@ func SendSMTP(cfg SMTPConfig, m OutgoingMessage) error {
|
||||
if err := c.Auth(auth); err != nil {
|
||||
return fmt.Errorf("smtp auth: %w", err)
|
||||
}
|
||||
if err := c.SendMail(m.From, m.Recipients(), bytes.NewReader(raw)); err != nil {
|
||||
if err := c.SendMail(envelopeFrom(m.From), m.Recipients(), bytes.NewReader(raw)); err != nil {
|
||||
return fmt.Errorf("smtp send: %w", err)
|
||||
}
|
||||
return c.Quit()
|
||||
|
||||
Reference in New Issue
Block a user