forked from alash3al/go-smtpsrv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.go
60 lines (47 loc) · 1.28 KB
/
server.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
48
49
50
51
52
53
54
55
56
57
58
59
60
package smtpsrv
import (
"crypto/tls"
"fmt"
"time"
"github.com/emersion/go-smtp"
)
type ServerConfig struct {
ListenAddr string
BannerDomain string
ReadTimeout time.Duration
WriteTimeout time.Duration
Handler HandlerFunc
Auther AuthFunc
MaxMessageBytes int
TLSConfig *tls.Config
}
func ListenAndServe(cfg *ServerConfig) error {
s := smtp.NewServer(NewBackend(cfg.Auther, cfg.Handler))
SetDefaultServerConfig(cfg)
s.Addr = cfg.ListenAddr
s.Domain = cfg.BannerDomain
s.ReadTimeout = cfg.ReadTimeout
s.WriteTimeout = cfg.WriteTimeout
s.MaxMessageBytes = cfg.MaxMessageBytes
s.AllowInsecureAuth = true
s.AuthDisabled = true
s.EnableSMTPUTF8 = false
fmt.Println("⇨ smtp server started on", s.Addr)
return s.ListenAndServe()
}
func ListenAndServeTLS(cfg *ServerConfig) error {
s := smtp.NewServer(NewBackend(cfg.Auther, cfg.Handler))
SetDefaultServerConfig(cfg)
s.Addr = cfg.ListenAddr
s.Domain = cfg.BannerDomain
s.ReadTimeout = cfg.ReadTimeout
s.WriteTimeout = cfg.WriteTimeout
s.MaxMessageBytes = cfg.MaxMessageBytes
s.AllowInsecureAuth = true
s.AuthDisabled = true
s.EnableSMTPUTF8 = false
s.EnableREQUIRETLS = true
s.TLSConfig = cfg.TLSConfig
fmt.Println("⇨ smtp server started on", s.Addr)
return s.ListenAndServeTLS()
}