1 Star 0 Fork 0

ichub / goconfig

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
email_helper.go 1003 Bytes
一键复制 编辑 原始数据 按行查看 历史
leijmdas 提交于 2024-03-25 15:25 . add
package stringutils
import (
"context"
"gitee.com/cristiane/micro-mall-api/vars"
"strings"
"sync"
"time"
)
var (
one sync.Once
DefaultEmailHelper *Client
)
func initVars() {
DefaultEmailHelper = NewClient(vars.EmailConfigSetting.User, vars.EmailConfigSetting.Password, vars.EmailConfigSetting.Host, vars.EmailConfigSetting.Port)
}
const maxRetrySendTimes = 3
const retryIdleTime = 500 * time.Millisecond
func SendEmailNotice(ctx context.Context, receivers, subject, msg string) error {
one.Do(func() {
initVars()
})
var err error
emailReq := &SendRequest{
Receivers: strings.Split(receivers, ","),
Subject: subject,
Message: msg,
}
// retry send email
for retryCount := 0; retryCount < maxRetrySendTimes; retryCount++ {
err = DefaultEmailHelper.SendEmail(emailReq)
if err == nil {
break
}
time.Sleep(retryIdleTime)
}
if err != nil {
vars.ErrorLogger.Errorf(ctx, "send email err: %v, req: %v", err, emailReq)
return err
}
return nil
}
1
https://gitee.com/ichub/goconfig.git
git@gitee.com:ichub/goconfig.git
ichub
goconfig
goconfig
v1.0.406

搜索帮助