Examples.
This commit is contained in:
parent
526873ea5d
commit
c214cd0c15
3 changed files with 50 additions and 2 deletions
48
example_test.go
Normal file
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
username = string(parts[0])
|
username = string(parts[1])
|
||||||
password = string(parts[2])
|
password = string(parts[2])
|
||||||
|
|
||||||
case "LOGIN":
|
case "LOGIN":
|
||||||
|
|
2
smtpd.go
2
smtpd.go
|
@ -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
|
package smtpd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
Loading…
Add table
Reference in a new issue