Skip to content

Go Package for Sending Email With Custom HTML Template

License

Notifications You must be signed in to change notification settings

purwokertodev/goemail

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-email

Build Status

Send Email with your custom template with Golang, easy and straight forward

Install

$ go get github.com/wuriyanto48/goemail

Result

alt text

Usage

  • 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")
    
    }

Authors

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%