-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support setting custom sender domain (#79)
* feat: support setting custom sender domain Some SMTP servers, such as the Gmail SMTP-relay, requires a proper domain name in the inital EHLO/HELO exchange and will reject attempts to use localhost. * ci: replace deprecated linters Switch deprecated linters to their suggested replacements. * fix: handle HELO errors when using localname Check the return value of the HELO when specifying a sender domain name. --------- Co-authored-by: Dom Dwyer <[email protected]>
- Loading branch information
Showing
6 changed files
with
124 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,10 +119,17 @@ func newConnAsserts(c net.Conn, t *testing.T) *connAsserts { | |
// mockMail provides the methods for a sendableMail, allowing for deterministic | ||
// MIME content in tests. | ||
type mockMail struct { | ||
toAddrs []string | ||
fromAddr string | ||
auth smtp.Auth | ||
mime string | ||
localName string | ||
toAddrs []string | ||
fromAddr string | ||
auth smtp.Auth | ||
mime string | ||
} | ||
|
||
// getLocalName should return the sender domain to be used in the EHLO/HELO | ||
// command. | ||
func (m *mockMail) getLocalName() string { | ||
return m.localName | ||
} | ||
|
||
// toAddrs should return a slice of email addresses to be added to the RCPT | ||
|
@@ -262,6 +269,48 @@ func TestSMTPProtocolExchange(t *testing.T) { | |
wantTLSErr: nil, | ||
wantPlaintextErr: nil, | ||
}, | ||
{ | ||
name: "with localname", | ||
mail: &mockMail{ | ||
toAddrs: []string{ | ||
"[email protected]", | ||
"[email protected]", | ||
"Dom <[email protected]>", | ||
}, | ||
fromAddr: "[email protected]", | ||
mime: "bananas", | ||
localName: "example.com", | ||
}, | ||
connFn: func(c *connAsserts) { | ||
c.Respond("220 localhost ESMTP bananas\r\n") | ||
|
||
c.Expect("EHLO example.com\r\n") | ||
c.Respond("250-example.com Hola\r\n") | ||
c.Respond("250 AUTH LOGIN PLAIN\r\n") | ||
|
||
c.Expect("MAIL FROM:<[email protected]>\r\n") | ||
c.Respond("250 OK\r\n") | ||
|
||
c.Expect("RCPT TO:<[email protected]>\r\n") | ||
c.Respond("250 OK\r\n") | ||
|
||
c.Expect("RCPT TO:<[email protected]>\r\n") | ||
c.Respond("250 OK\r\n") | ||
|
||
c.Expect("RCPT TO:<[email protected]>\r\n") | ||
c.Respond("250 OK\r\n") | ||
|
||
c.Expect("DATA\r\n") | ||
c.Respond("354 OK\r\n") | ||
c.Expect("bananas\r\n.\r\n") | ||
c.Respond("250 Will do friend\r\n") | ||
|
||
c.Expect("QUIT\r\n") | ||
c.Respond("221 Adios\r\n") | ||
}, | ||
wantTLSErr: nil, | ||
wantPlaintextErr: nil, | ||
}, | ||
} | ||
|
||
// handleConn provides the accept loop for both the TLS server, and the | ||
|
@@ -282,7 +331,7 @@ func TestSMTPProtocolExchange(t *testing.T) { | |
} | ||
|
||
for _, tt := range tests { | ||
var tt = tt | ||
tt := tt | ||
t.Run(tt.name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters