git » chasquid » commit afd79df

courier: Always have a domain for EHLO/HELO

author Alberto Bertogli
2016-10-03 00:03:55 UTC
committer Alberto Bertogli
2016-10-09 23:51:05 UTC
parent 0e4182177969c2a0dc6df53870442d5c54d85752

courier: Always have a domain for EHLO/HELO

In the SMTP courier, we should always include a domain when saying hello, as
many MTAs will be pick about it.

An empty domain can happen if the envelope-from is <>. In that case, we fall
back to our hostname.

internal/courier/smtp.go +5 -0

diff --git a/internal/courier/smtp.go b/internal/courier/smtp.go
index 8c5f7f7..43361c6 100644
--- a/internal/courier/smtp.go
+++ b/internal/courier/smtp.go
@@ -4,6 +4,7 @@ import (
 	"crypto/tls"
 	"flag"
 	"net"
+	"os"
 	"time"
 
 	"github.com/golang/glog"
@@ -69,6 +70,10 @@ retry:
 	if err != nil {
 		return tr.Errorf("Sender domain not IDNA compliant: %v", err), true
 	}
+	if fromDomain == "" {
+		// This can happen when sending bounces. Last resort.
+		fromDomain, _ = os.Hostname()
+	}
 	if err = c.Hello(fromDomain); err != nil {
 		return tr.Errorf("Error saying hello: %v", err), false
 	}