Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new field Banner in Server struct for custom smtp greeting text #132

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down