git » chasquid » commit 2f2d1f2

courier: Use the senders' domain when saying EHLO

author Alberto Bertogli
2016-10-01 17:00:53 UTC
committer Alberto Bertogli
2016-10-09 23:51:04 UTC
parent 280939c3ec46607cb15b78d19de43a3971a92424

courier: Use the senders' domain when saying EHLO

Some servers, like postfix, will pay close attention to the domain we say as a
part of the EHLO.

By default, Go's smtp package will use "localhost", causing it to complain.

This patch fixes that by using the envelope-from's domain.
It's not clear if that's better than using what we are resolving to, but
that's much more involved so we're going to do this for now.

internal/courier/smtp.go +6 -0
internal/courier/smtp_test.go +5 -5

diff --git a/internal/courier/smtp.go b/internal/courier/smtp.go
index 5ef5c4b..28f2206 100644
--- a/internal/courier/smtp.go
+++ b/internal/courier/smtp.go
@@ -67,6 +67,12 @@ retry:
 		return tr.Errorf("Error creating client: %v", err), false
 	}
 
+	// Issue an EHLO with a valid domain; otherwise, some servers like postfix
+	// will complain.
+	if err = c.Hello(envelope.DomainOf(from)); err != nil {
+		return tr.Errorf("Error saying hello: %v", err), false
+	}
+
 	// TODO: Keep track of hosts and MXs that we've successfully done TLS
 	// against, and enforce it.
 	if ok, _ := c.Extension("STARTTLS"); ok {
diff --git a/internal/courier/smtp_test.go b/internal/courier/smtp_test.go
index 9324e1a..915b09c 100644
--- a/internal/courier/smtp_test.go
+++ b/internal/courier/smtp_test.go
@@ -59,7 +59,7 @@ func TestSMTP(t *testing.T) {
 
 	responses := map[string]string{
 		"_welcome":          "220 welcome\n",
-		"EHLO localhost":    "250 ehlo ok\n",
+		"EHLO me":           "250 ehlo ok\n",
 		"MAIL FROM:<me@me>": "250 mail ok\n",
 		"RCPT TO:<to@to>":   "250 rcpt ok\n",
 		"DATA":              "354 send data\n",
@@ -93,14 +93,14 @@ func TestSMTPErrors(t *testing.T) {
 		// MAIL FROM not allowed.
 		{
 			"_welcome":          "220 mail from not allowed\n",
-			"EHLO localhost":    "250 ehlo ok\n",
+			"EHLO me":           "250 ehlo ok\n",
 			"MAIL FROM:<me@me>": "501 mail error\n",
 		},
 
 		// RCPT TO not allowed.
 		{
 			"_welcome":          "220 rcpt to not allowed\n",
-			"EHLO localhost":    "250 ehlo ok\n",
+			"EHLO me":           "250 ehlo ok\n",
 			"MAIL FROM:<me@me>": "250 mail ok\n",
 			"RCPT TO:<to@to>":   "501 rcpt error\n",
 		},
@@ -108,7 +108,7 @@ func TestSMTPErrors(t *testing.T) {
 		// DATA error.
 		{
 			"_welcome":          "220 data error\n",
-			"EHLO localhost":    "250 ehlo ok\n",
+			"EHLO me":           "250 ehlo ok\n",
 			"MAIL FROM:<me@me>": "250 mail ok\n",
 			"RCPT TO:<to@to>":   "250 rcpt ok\n",
 			"DATA":              "554 data error\n",
@@ -117,7 +117,7 @@ func TestSMTPErrors(t *testing.T) {
 		// DATA response error.
 		{
 			"_welcome":          "220 data response error\n",
-			"EHLO localhost":    "250 ehlo ok\n",
+			"EHLO me":           "250 ehlo ok\n",
 			"MAIL FROM:<me@me>": "250 mail ok\n",
 			"RCPT TO:<to@to>":   "250 rcpt ok\n",
 			"DATA":              "354 send data\n",