-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.go
46 lines (38 loc) · 907 Bytes
/
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
package meilo
import (
"fmt"
"log"
"time"
"github.com/emersion/go-smtp"
)
type server struct {
Port string
Password string
User string
Host string
}
func (bkd *server) NewSession(c *smtp.Conn) (smtp.Session, error) {
return &session{
username: bkd.User,
password: bkd.Password,
}, nil
}
func (bkd *server) Addr() string {
return bkd.Host + ":" + bkd.Port
}
// Start starts the SMTP server with the given options.
func (bkd *server) run() error {
stp := smtp.NewServer(bkd)
stp.Addr = bkd.Host + ":" + bkd.Port
stp.Domain = bkd.Host
stp.WriteTimeout = 10 * time.Second
stp.ReadTimeout = 10 * time.Second
stp.MaxMessageBytes = 1024 * 1024
stp.MaxRecipients = 50
stp.AllowInsecureAuth = true
log.Println("Starting SMTP server at", stp.Addr)
if err := stp.ListenAndServe(); err != nil {
return fmt.Errorf("meilo: failed to start server: %v", err)
}
return nil
}