本文整理匯總了Golang中bitbucket/org/chrj/smtpd.Server類的典型用法代碼示例。如果您正苦於以下問題:Golang Server類的具體用法?Golang Server怎麽用?Golang Server使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Server類的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExampleServer
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(
"",
"[email protected]",
"password",
"smtp.gmail.com",
),
env.Sender,
env.Recipients,
env.Data,
)
},
}
server.ListenAndServe("127.0.0.1:10025")
}
示例2: runsslserver
func runsslserver(t *testing.T, server *smtpd.Server) (addr string, closer func()) {
cert, err := tls.X509KeyPair(localhostCert, localhostKey)
if err != nil {
t.Fatalf("Cert load failed: %v", err)
}
server.TLSConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
}
return runserver(t, server)
}
示例3: runserver
func runserver(t *testing.T, server *smtpd.Server) (addr string, closer func()) {
ln, err := net.Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Fatalf("Listen failed: %v", err)
}
go func() {
server.Serve(ln)
}()
done := make(chan bool)
go func() {
<-done
ln.Close()
}()
return ln.Addr().String(), func() {
done <- true
}
}