dev: add retry for send email

This commit is contained in:
bryan 2025-07-02 12:20:13 +08:00
parent da6a19186f
commit 3989c492db

View File

@ -69,6 +69,8 @@ func New(cfg Config) *EmailPlainAuthSender {
to string
name string
body string
retry int
}
var whiteListRegs = []*regexp.Regexp{}
@ -98,7 +100,7 @@ func New(cfg Config) *EmailPlainAuthSender {
var emailQueue = make(chan emailItem, 1024)
var emailSendFunc = func(to string, name, body string) (err error) {
eml := emailItem{to, name, body}
eml := emailItem{to, name, body, 0}
emailQueue <- eml
return nil
}
@ -139,6 +141,13 @@ func New(cfg Config) *EmailPlainAuthSender {
log.Infof("to[%v],from[%s]", m.To, m.From)
log.Infof("smtpUser[%s],smtpPass[%s],smtpAddr[%s:%s],smtpProxy[%s]",
smtpUser, secLogPass(smtpPass), smtpAddr, smtpPort, secLogProxy(cfg.SmtpProxy))
if eml.retry < 5 {
go func() {
eml.retry++
time.Sleep(time.Duration(5*eml.retry) * time.Second)
emailQueue <- eml
}()
}
continue
}
log.Infof("success send email to [%s]", eml.to)