I'm a beginner in Go and Echo. I am required to store a html template(email template) , which will also have some details passed as context. So that it can be stored into body column (text in MySQL) and will be triggered later.
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")
}
}
The EmailJob
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)
}
body := c.Render(http.StatusOK,"email/user_notify_email.html",visitingDetails)
this line gives error as it returns an error for render. I am not sure how I will I do it? I hope I made it clear. A little help will be much appreciated.