This commit is contained in:
eson 2023-09-04 13:29:36 +08:00
parent 336e4708d1
commit c062848a95
4 changed files with 22 additions and 4 deletions

View File

@ -1,12 +1,13 @@
Subject: Please confirm your {{ .CompanyName }} account
Dear,
Dear {{ .UserName }},
Thank you for registering an account with {{ .CompanyName }}. We are thrilled to have you join our community!
Please take a moment to confirm your email address by clicking the button below so we can activate your account:
<a href="{{ .ConfirmationLink }}" target="_blank" style="background-color: #008CBA; color: #FFFFFF; text-decoration: none; padding: 10px 15px; border-radius: 3px; display:inline-block; font-weight: bold;">Confirm My Account</a>
<a href="{{ .ConfirmationLink }}" target="_blank" style="background-color: #008CBA; color: #FFFFFF; text-decoration: none; padding: 10px 15px; border-radius: 3px; display:inline-block; font-weight: bold;">Confirm Account: .UserName</a>
Confirming your email ensures your account is properly secured. This also lets you access member-only tools and content.

View File

@ -58,6 +58,7 @@ type EmailFormat struct {
ConfirmationLink string // fs确认连接
SenderName string // 发送人
SenderTitle string // 发送标题
Extend map[string]string
}
// EmailSender
@ -110,7 +111,12 @@ func (m *EmailSender) ProcessEmailTasks() {
go func() {
defer func() { <-m.semaphore }() // Release a token
content := RenderEmailTemplate(emailformat.CompanyName, emailformat.ConfirmationLink, emailformat.SenderName, emailformat.SenderTitle)
content := RenderEmailRegisterTemplate(emailformat.CompanyName,
emailformat.ConfirmationLink,
emailformat.SenderName,
emailformat.SenderTitle,
emailformat.Extend,
)
err := smtp.SendMail("smtp.gmail.com:587", m.Auth, m.FromEmail, []string{emailformat.TargetEmail}, content)
if err != nil {
log.Printf("Failed to send email to %s: %v\n", emailformat, err)
@ -156,7 +162,7 @@ func (m *EmailSender) ClearExpiredTasks() {
}
}
func RenderEmailTemplate(companyName, confirmationLink, senderName, senderTitle string) []byte {
func RenderEmailRegisterTemplate(companyName, confirmationLink, senderName, senderTitle string, extend map[string]string) []byte {
data := map[string]string{
"CompanyName": companyName,
@ -165,6 +171,10 @@ func RenderEmailTemplate(companyName, confirmationLink, senderName, senderTitle
"SenderTitle": senderTitle,
}
for k, v := range extend {
data[k] = v
}
var result bytes.Buffer
err := tpls.ExecuteTemplate(&result, "email_register.tpl", data)
if err != nil {

View File

@ -72,6 +72,7 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
return resp.SetStatus(basic.CodeOAuthRegisterTokenErr)
}
userName := token.Extend["first_name"].(string) + " " + token.Extend["last_name"].(string)
// 进入发送邮箱的系统
EmailManager.EmailTasks <- &EmailFormat{
UniqueKey: "register-" + req.Email,
@ -80,6 +81,9 @@ func (l *UserEmailRegisterLogic) UserEmailRegister(req *types.RequestEmailRegist
ConfirmationLink: clurl,
SenderName: "support@fusenpack.com",
SenderTitle: "register-valid",
Extend: map[string]string{
"UserName": userName,
},
} // email进入队
return resp.SetStatus(basic.CodeOK)

View File

@ -80,6 +80,9 @@ func (l *UserRegisterLogic) UserRegister(req *types.RequestUserRegister, userinf
ConfirmationLink: clurl,
SenderName: "support@fusenpack.com",
SenderTitle: "register-valid",
Extend: map[string]string{
"UserName": req.FirstName + " " + req.LastName,
},
} // email进入队
return resp.SetStatus(basic.CodeOK)