dev: add retry for send email
This commit is contained in:
parent
da6a19186f
commit
3989c492db
@ -69,6 +69,8 @@ func New(cfg Config) *EmailPlainAuthSender {
|
|||||||
to string
|
to string
|
||||||
name string
|
name string
|
||||||
body string
|
body string
|
||||||
|
|
||||||
|
retry int
|
||||||
}
|
}
|
||||||
|
|
||||||
var whiteListRegs = []*regexp.Regexp{}
|
var whiteListRegs = []*regexp.Regexp{}
|
||||||
@ -98,7 +100,7 @@ func New(cfg Config) *EmailPlainAuthSender {
|
|||||||
|
|
||||||
var emailQueue = make(chan emailItem, 1024)
|
var emailQueue = make(chan emailItem, 1024)
|
||||||
var emailSendFunc = func(to string, name, body string) (err error) {
|
var emailSendFunc = func(to string, name, body string) (err error) {
|
||||||
eml := emailItem{to, name, body}
|
eml := emailItem{to, name, body, 0}
|
||||||
emailQueue <- eml
|
emailQueue <- eml
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -139,6 +141,13 @@ func New(cfg Config) *EmailPlainAuthSender {
|
|||||||
log.Infof("to[%v],from[%s]", m.To, m.From)
|
log.Infof("to[%v],from[%s]", m.To, m.From)
|
||||||
log.Infof("smtpUser[%s],smtpPass[%s],smtpAddr[%s:%s],smtpProxy[%s]",
|
log.Infof("smtpUser[%s],smtpPass[%s],smtpAddr[%s:%s],smtpProxy[%s]",
|
||||||
smtpUser, secLogPass(smtpPass), smtpAddr, smtpPort, secLogProxy(cfg.SmtpProxy))
|
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
|
continue
|
||||||
}
|
}
|
||||||
log.Infof("success send email to [%s]", eml.to)
|
log.Infof("success send email to [%s]", eml.to)
|
||||||
|
Loading…
Reference in New Issue
Block a user