-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathexample_test.go
47 lines (37 loc) · 866 Bytes
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package smtpd_test
import (
"errors"
"net/smtp"
"strings"
"github.com/chrj/smtpd"
)
func ExampleServer() {
var server *smtpd.Server
// No-op server. Accepts and discards
server = &smtpd.Server{}
server.ListenAndServe("127.0.0.1:10025")
// Relay server. Accepts only from single IP address and forwards using the Gmail smtp
server = &smtpd.Server{
HeloChecker: func(peer smtpd.Peer, name string) 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.ListenAndServe("127.0.0.1:10025")
}