-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
33 lines (28 loc) · 912 Bytes
/
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
package smtp
import (
"context"
"sync"
gologger "github.com/wawakakakyakya/GolangLogger"
)
func Main(host string, port int, userName string, password string, timeout int, from string, queue chan *SMTPData, cancelCtx context.Context, logger *gologger.Logger, wg *sync.WaitGroup) {
defer wg.Done()
smtpLogger := logger.Child("smtpMain")
smtpLogger.Debug("start sendMail process")
smtpClient := NewSMTPClient(host, port, userName, password, timeout, from, smtpLogger)
for {
smtpLogger.Info("waiting mailqueue...")
select {
case smtpData := <-queue:
smtpLogger.Info("send mail")
smtpLogger.DebugF("process smtpDate: %v", smtpData)
if err := smtpClient.Send(smtpData); err != nil {
smtpLogger.Error("send mail failed")
smtpLogger.Error(err.Error())
}
smtpLogger.Info("mail done")
case <-cancelCtx.Done():
smtpLogger.Info("sendmail process was ended")
return
}
}
}