Go Language
Go Language

Sending Emails in Go using SimpleMailer



Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

Warning: WP_Syntax::substituteToken(): Argument #1 ($match) must be passed by reference, value given in /usr/www/phpsites/public/yayprogramming/wp-content/plugins/wp-syntax/wp-syntax.php on line 383

I have been working on a Go Language package called SimpleMailer that allows variables to be injected into the HTML template of an email. It uses {{VAR}} and replaces with a string.

Go Get the package

1
go get github.com/hunterlong/simplemailer

Import the package in your application

1
import "github.com/hunterlong/simplemailer"

Initialize your SMTP credentials, you can use Amazon SES, Gmail, Yahoo, etc…
Insert this inside your main() { }

1
2
// SMTP host, port, username, password, name, send from address, email directory
SimpleMailer.SetSMTPInfo("emailserveraddress.com", "465", "info@domain.com", "passwordhere", "Sender Name", "from@domain.com", "./emails/")

Create a nice HTML template. Name it “welcome.html”

1
2
Hello {{USERNAME}},
Thank you for joining {{WEBSITE}}. I hope you enjoy!

Send your email with SimpleMailer!

1
2
3
4
5
6
7
8
9
10
11
outVars := SimpleMailer.Variables{map[string]interface{}{
                    "USERNAME":"supercool", 
                    "WEBSITE": "yayprogramming.com",
}}
newOutgoing := SimpleMailer.Outgoing{
                    Email: "info@domain.com", 
                    Subject: "SimpleMailer in Golang", 
                    Template: "welcome.html", 
                    Variables: outVars }
sendSuccess := SimpleMailer.SendSingle(newOutgoing)
fmt.Println(sendSuccess) //true of false

This Golang package can be useful for sending quick emails with simple variables inside of them. Everything from Forgot Password emails, transaction emails, Email confirmations, and everything in between.


View Comments
There are currently no comments.