package main import ( "flag" "fmt" "log" "code.osinet.fr/fgm/smtpd" baseSmtpd "github.com/bradfitz/go-smtpd/smtpd" ) func onNewConnection(c baseSmtpd.Connection) error { var err error log.Printf("New connection from %v\n", c.Addr()) network := c.Addr().Network() if network != "tcp" { err = fmt.Errorf("unsupported network: %v", network) } return err } func onNewMail(c baseSmtpd.Connection, addr baseSmtpd.MailAddress) (baseSmtpd.Envelope, error) { var err error e := smtpd.DemoEnvelope{ SmtpNetwork: c.Addr().Network(), SmtpRemote: c.Addr().String(), MailFrom: addr, } return &e, err } func main() { var addr string flag.StringVar(&addr, "addr", ":25", "The address on which to listen.") flag.Parse() s := baseSmtpd.Server{ Addr: addr, OnNewConnection: onNewConnection, OnNewMail: onNewMail, } err := s.ListenAndServe() if err != nil { log.Fatalf("ListenAndServe: %v\n", err) } }