Skip to content

Implementation of RFC 5321 for SMTP server applications

Notifications You must be signed in to change notification settings

hectane/go-smtpsrv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-smtpsrv

Build Status GoDoc MIT License

Golang provides an SMTP client implementation in the net/smtp package, but it lacks an implementation of an SMTP server. This package is based on RFC 5321 and attempts to bridge that gap.

Using go-smtpsrv

To use the package in your project, import the following package:

import "github.com/hectane/go-smtpsrv"

To begin receiving SMTP connections from clients, create an instance of smtpsrv.Server:

s, err := smtpsrv.NewServer(&smtpsrv.Config{
    Addr: ":smtp",
    Banner: "SuperAwesomeServer",
    ReadTimeout: 2 * time.Minute,
})

The banner is used to greet clients and the read timeout determines how long the server will wait for the client to send a command before timing out and disconnecting them.

The server provides a channel that must be used for receiving messages:

go func() {
    for m := range s.NewMessage {
        // do something with the message
    }
}()

To close the server and wait for it to shut down:

s.Close(false)

To shut down immediately and forcefully disconnect all clients without allowing them to finish, use true for the parameter passed to Close().

About

Implementation of RFC 5321 for SMTP server applications

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages