smtpd is a pure Go implementation of an SMTP server. It allows you to do things like:
package main
import (
"fmt"
"net/smtp"
"github.com/mailproto/smtpd"
)
var helloWorld = `To: [email protected]
From: [email protected]
Content-Type: text/plain
This is the email body`
func main() {
var server *smtpd.Server
server = smtpd.NewServer(func(msg *smtpd.Message) error {
fmt.Println("Got message from:", msg.From)
fmt.Println(string(msg.RawBody))
return server.Close()
})
go server.ListenAndServe(":2525")
<-server.Ready
log.Fatal(smtp.SendMail(server.Address(), nil, "[email protected]", []string{"[email protected]"}, []byte(helloWorld)))
}
@todo document