123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- 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)
- }
- }
|