我是 Go 和 Echo 的初学者。我需要存储一个 html 模板(电子邮件模板),它还将包含一些作为上下文传递的详细信息。以便它可以存储到正文列(MySQL 中的文本)并稍后触发。
if user.Email !=""{
visitingDetails := H{"user_name" : user.Fname,
"location" : location.Name,
"visitor_company": visitor.Company,
"visitor_name" : visitor.Fname +" "+visitor.Lname,
"visitor_phone" : visitor.Phone,
"visitor_email" : visitor.Email,
"visitor_fname" : visitor.Fname,
"visitor_image" : visitor.ProfilePicture,
}
subject := visitor.Fname +" has come to visit you at the reception"
body := c.Render(http.StatusOK,"email/user_notify_email.html",visitingDetails)
emailJob := models.EmailJob{Recipients: visitor.Email , Subject: subject, Body: body}
db.Create(&emailJob)
if db.NewRecord(emailJob){
fmt.Println("Unable to send email")
}
}
电子邮件工作
type EmailJob struct {
Id int
Recipients string
Subject string
Body string
Sent int
Error string
}
func (t *Template) Render(w io.Writer, name string, data interface{}, c echo.Context) error {
return t.templates.ExecuteTemplate(w, name, data)
}
正文 := c.Render(http.StatusOK,"email/user_notify_email.html",visitingDetails)
此行给出错误,因为它返回渲染错误。我不知道我会怎么做?我希望我说清楚了。一点帮助将不胜感激。