Skip to content

Commit

Permalink
Fix e-mail From/Return-Path envelope sender. Closes #908, closes #1008.
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Nov 9, 2022
1 parent c2d41e0 commit 74322cd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/knadh/go-pop3 v0.3.0
github.com/knadh/goyesql/v2 v2.1.2
github.com/knadh/koanf v1.2.3
github.com/knadh/smtppool v1.0.0
github.com/knadh/smtppool v1.0.1
github.com/knadh/stuffbin v1.1.0
github.com/labstack/echo/v4 v4.9.0
github.com/lib/pq v1.10.3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ github.com/knadh/koanf v1.2.3 h1:2Rkr0YhhYk+4QEOm800Q3Pu0Wi87svTxM6uuEb4WhYw=
github.com/knadh/koanf v1.2.3/go.mod h1:xpPTwMhsA/aaQLAilyCCqfpEiY1gpa160AiCuWHJUjY=
github.com/knadh/smtppool v1.0.0 h1:1c8A7+nD8WdMMzvd3yY5aoY9QBgyGTA+Iq1IdlgKGJw=
github.com/knadh/smtppool v1.0.0/go.mod h1:3DJHouXAgPDBz0kC50HukOsdapYSwIEfJGwuip46oCA=
github.com/knadh/smtppool v1.0.1 h1:gNASLB4x4W5jhVHRApwr9d2xSpsuannAFJVt/bVR8pA=
github.com/knadh/smtppool v1.0.1/go.mod h1:3DJHouXAgPDBz0kC50HukOsdapYSwIEfJGwuip46oCA=
github.com/knadh/stuffbin v1.1.0 h1:f5S5BHzZALjuJEgTIOMC9NidEnBJM7Ze6Lu1GHR/lwU=
github.com/knadh/stuffbin v1.1.0/go.mod h1:yVCFaWaKPubSNibBsTAJ939q2ABHudJQxRWZWV5yh+4=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
Expand Down
25 changes: 17 additions & 8 deletions internal/messenger/email/email.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import (
"github.com/knadh/smtppool"
)

const emName = "email"
const (
emName = "email"
hdrReturnPath = "Return-Path"
)

// Server represents an SMTP server's credentials.
type Server struct {
Expand Down Expand Up @@ -125,16 +128,22 @@ func (e *Emailer) Push(m messenger.Message) error {
}

em.Headers = textproto.MIMEHeader{}

// Attach SMTP level headers.
for k, v := range srv.EmailHeaders {
em.Headers.Set(k, v)
}

// Attach e-mail level headers.
if len(m.Headers) > 0 {
em.Headers = m.Headers
for k, v := range m.Headers {
em.Headers.Set(k, v[0])
}

// Attach SMTP level headers.
if len(srv.EmailHeaders) > 0 {
for k, v := range srv.EmailHeaders {
em.Headers.Set(k, v)
}
// If the `Return-Path` header is set, it should be set as the
// the SMTP envelope sender (via the Sender field of the email struct).
if sender := em.Headers.Get(hdrReturnPath); sender != "" {
em.Sender = sender
em.Headers.Del(hdrReturnPath)
}

switch m.ContentType {
Expand Down

0 comments on commit 74322cd

Please sign in to comment.