-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (51 loc) · 1.05 KB
/
main.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
package main
import (
"crypto/tls"
"log"
"os"
"time"
"github.com/emersion/go-smtp"
)
func main() {
// Create a smtp sever instance
b := &Backend{}
if err := b.init(); err != nil {
log.Fatalln(err)
return
}
srv := smtp.NewServer(b)
// Setup TLS if needed
certFile := os.Getenv("SMTP_PROXY_CERT")
keyFile := os.Getenv("SMTP_PROXY_KEY")
if certFile != "" && keyFile != "" {
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
log.Fatalln(err)
return
}
srv.TLSConfig = &tls.Config{
Certificates: []tls.Certificate{cert},
}
}
// Setup Port
port := os.Getenv("SMTP_PROXY_PORT")
if port == "" {
if srv.TLSConfig != nil {
port = "587"
} else {
port = "25"
}
}
srv.Addr = ":" + port
srv.Domain = ""
srv.ReadTimeout = 10 * time.Second
srv.WriteTimeout = 10 * time.Second
srv.MaxMessageBytes = 1024 * 1024
srv.MaxLineLength = 4000
srv.MaxRecipients = 50
srv.AllowInsecureAuth = true
log.Printf("Start to listen on \"%s\"", srv.Addr)
if err := srv.ListenAndServe(); err != nil {
log.Fatalln(err)
}
}