7 "github.com/matcornic/hermes"
11 var MailTemplateEngine hermes.Hermes
13 func ConfigureMailTemplateEngine() {
15 if strings.Contains(CONFIG.Domain, "localhost") {
16 link = fmt.Sprintf("http://%s", CONFIG.Domain)
18 link = fmt.Sprintf("https://%s", CONFIG.Domain)
21 MailTemplateEngine = hermes.Hermes{
22 Product: hermes.Product{
25 Copyright: "Copyright © 2017 CryptoPF. All rights reserved.",
30 func SendResetPasswordMail(to, token string) error {
35 "You have received this email because a password reset request for your CryptoPF account was received.",
37 Actions: []hermes.Action{
39 Instructions: "Click the button below to reset your password:",
40 Button: hermes.Button{
42 Text: "Reset your password",
43 Link: fmt.Sprintf("%s/change-password?token=%s", MailTemplateEngine.Product.Link, token),
48 "If you did not request a password reset, no further action is required on your part.",
54 body, err := MailTemplateEngine.GenerateHTML(mail)
59 return SendEmail(to, "Password reset", body)
62 func SendConfirmationMail(to, token string) error {
67 "Welcome to CryptoPF! We're very excited to have you on board.",
69 Actions: []hermes.Action{
71 Instructions: "To get started with CryptoPF, please click here:",
72 Button: hermes.Button{
73 Text: "Confirm your account",
74 Link: fmt.Sprintf("%s/confirm?token=%s", MailTemplateEngine.Product.Link, token),
79 "Need help, or have questions? Just reply to this email, we'd love to help.",
85 body, err := MailTemplateEngine.GenerateHTML(mail)
90 return SendEmail(to, "Confirm your email", body)
93 func SendEmail(to, subject, body string) error {
94 m := gomail.NewMessage()
95 m.SetAddressHeader("From", MAIL_CONFIG.AddressFrom, "CryptoPF")
96 m.SetAddressHeader("To", to, to)
97 m.SetHeader("Subject", subject)
98 m.SetBody("text/html", body)
100 d := gomail.NewPlainDialer(MAIL_CONFIG.SmtpAddress, 587, MAIL_CONFIG.Login, MAIL_CONFIG.Password)
102 return d.DialAndSend(m)