Examples.

This commit is contained in:
Christian Joergensen 2014-07-14 20:44:14 +02:00
parent b78de3a03e
commit 587b6ad4ac
3 changed files with 50 additions and 2 deletions

48
example_test.go Normal file

@ -0,0 +1,48 @@
package smtpd
import (
"bitbucket.org/chrj/smtpd"
"errors"
"net"
"net/smtp"
"strings"
)
func ExampleServer() {
// No-op server. Accepts and discards
server := &smtpd.Server{}
server.serve()
// Relay server. Accepts only from single IP address and forwards using the Gmail smtp
server := &smtpd.Server{
Addr: "0.0.0.0:10025",
HeloChecker: func(peer smtpd.Peer) error {
if !strings.HasPrefix(peer.Addr.String(), "42.42.42.42:") {
return errors.New("Denied")
}
return nil
},
Handler: func(peer smtpd.Peer, env smtpd.Envelope) error {
return smtp.SendMail(
"smtp.gmail.com:587",
smtp.PlainAuth(
"",
"username@gmail.com",
"password",
"smtp.gmail.com",
),
env.Sender,
env.Recipients,
env.Data,
)
},
}
server.serve()
}

@ -343,7 +343,7 @@ func (session *session) handleAUTH(cmd command) {
return
}
username = string(parts[0])
username = string(parts[1])
password = string(parts[2])
case "LOGIN":

@ -1,4 +1,4 @@
// Package smtpd implements a SMTP server with support for STARTTLS, authentication and restrictions on the different stages of the SMTP session.
// Package smtpd implements a SMTP server with support for STARTTLS, authentication (PLAIN/LOGIN) and optional restrictions on the different stages of the SMTP session.
package smtpd
import (