matcornic / hermes

Golang package that generates clean, responsive HTML e-mails for sending transactional mail

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

HTML Email Body not working

anisbhsl opened this issue · comments

HTML message body generated using the example given was not rendered by gmail properly. Code I have tried so far:

h:=hermes.Hermes{
			//Theme: hermes.Theme,
			Product:            hermes.Product{
				Name:"XYZ",
				Link:"https://xyz.com",
				Copyright: fmt.Sprintf("Copyright © %d XYZ All rights reserved.",time.Now().Year()),
				TroubleText: "",
			},
		}

		emailBody,_:=h.GenerateHTML(hermes.Email{
			Body:hermes.Body{
				Name:         "bhusal.anish12",
				Intros:       []string{"Don't worry we have got you covered"},
				Dictionary:   nil,
				Table:        hermes.Table{},
				Actions: []hermes.Action{
					{
						Instructions: "To reset your account, please click here:",
						Button: hermes.Button{
							Color: "#22BC66", // Optional action button color
							Text:  "Reset Password",
							Link:  "https://xyz.com",
						},
					},
				},
				Outros: []string{
					"Need help, or have questions? Just reply to this email, we'd love to help.",
				},
				Greeting:     "",
				Signature:    "",
				Title:        "",
				FreeMarkdown: "",
			},
		})

This when sent via gmail client for go is not rendering the template.

The issue was due to invalid MIME configuration. I changed to following:

"From:" + from + "\r\n" +
			"To:" + to + "\r\n" +
			"Subject:" + subject + "!\n" +
			"MIME-version: 1.0;\nContent-Type: text/html; charset=\"UTF-8\";\n\n"+
			message

Now it's working as expected!