Send Email with your custom template with Golang, easy and straight forward
$ go get github.com/wuriyanto48/goemail
-
Example Html Email Template or using this awesome template https://github.com/leemunroe/responsive-html-email-template
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> </head> <body> <p> Hi {{.Username}} <h4>Your Account Registration Success</h4> <p>Please follow link bellow, to complete your Registration</p> <a href="{{.URL}}">Confirm email address</a> </p> </body> </html>
-
Golang Code
package main import ( "fmt" "github.com/wuriyanto48/goemail" ) func main() { authEmail := "[email protected]" authPassword := "your email password" authHost := "smtp.gmail.com" address := "smtp.gmail.com:587" to := []string{"[email protected]"} from := "[email protected]" subject := "Golang email" body := "Golang email sent..." email := goemail.New(to, address, from, subject, body, authEmail, authPassword, authHost) emailData := struct { Username string URL string }{ Username: "Wuriyanto", URL: "wuriyanto.com", } err := goemail.Execute(email, "template.html", emailData) if err != nil { fmt.Println(err) } fmt.Println("email sent") }
- Lone Wolf https://github.com/wuriyanto48