diff --git a/conn.go b/conn.go index 8ecd273..0439e2e 100644 --- a/conn.go +++ b/conn.go @@ -140,7 +140,7 @@ func (c *Conn) handle(cmd string, arg string) { case "DATA": c.handleData(arg) case "QUIT": - c.WriteResponse(221, EnhancedCode{2, 0, 0}, "Goodnight and good luck") + c.WriteResponse(221, EnhancedCode{2, 0, 0}, "Bye") c.Close() case "AUTH": if c.server.AuthDisabled { @@ -934,7 +934,7 @@ func (c *Conn) Reject() { } func (c *Conn) greet() { - c.WriteResponse(220, NoEnhancedCode, fmt.Sprintf("%v ESMTP Service Ready", c.server.Domain)) + c.WriteResponse(220, NoEnhancedCode, c.server.Banner) } func (c *Conn) WriteResponse(code int, enhCode EnhancedCode, text ...string) { diff --git a/example_test.go b/example_test.go index 607c971..6bb881e 100644 --- a/example_test.go +++ b/example_test.go @@ -140,6 +140,7 @@ func ExampleNewServer() { s.Addr = ":1025" s.Domain = "localhost" + s.Banner = s.Domain + " ESMTP Server Ready" s.WriteTimeout = 10 * time.Second s.ReadTimeout = 10 * time.Second s.MaxMessageBytes = 1024 * 1024 diff --git a/server.go b/server.go index a7c37c9..e3dc078 100644 --- a/server.go +++ b/server.go @@ -45,6 +45,9 @@ type Server struct { ReadTimeout time.Duration WriteTimeout time.Duration + // The text that follows the 220 status code in the SMTP greeting banner. + Banner string + // Advertise SMTPUTF8 (RFC 6531) capability. // Should be used only if backend supports it. EnableSMTPUTF8 bool @@ -75,7 +78,7 @@ type Server struct { // New creates a new SMTP server. func NewServer(be Backend) *Server { - return &Server{ + s := &Server{ // Doubled maximum line length per RFC 5321 (Section 4.5.3.1.6) MaxLineLength: 2000, @@ -103,6 +106,14 @@ func NewServer(be Backend) *Server { }, conns: make(map[*Conn]struct{}), } + + if s.Banner == "" { + s.Banner = s.Domain + " ESMTP Service Ready" + } else { + s.Banner = s.Domain + " " + s.Banner + } + + return s } // Serve accepts incoming connections on the Listener l. diff --git a/server_test.go b/server_test.go index f2bfe9f..a92f2b7 100644 --- a/server_test.go +++ b/server_test.go @@ -171,7 +171,7 @@ func testServer(t *testing.T, fn ...serverConfigureFunc) (be *backend, s *smtp.S be = new(backend) s = smtp.NewServer(be) - s.Domain = "localhost" + s.Banner = "localhost ESMTP Service Ready" s.AllowInsecureAuth = true for _, f := range fn { f(s) @@ -728,7 +728,6 @@ func testStrictServer(t *testing.T) (s *smtp.Server, c net.Conn, scanner *bufio. } s = smtp.NewServer(new(backend)) - s.Domain = "localhost" s.AllowInsecureAuth = true s.AuthDisabled = true s.Strict = true