An extremely simple SMTP emailing solution for your Go Language application. This golang package allows you to create a HTML email templates, and have variables inside of it by including {{USERNAME}} to be replaced by the actual username in the array. Simple Mailer can also send bulk emails without variables, checkout this package and try it out!
go get github.com/hunterlong/simplemailer
import "github.com/hunterlong/simplemailer"
You just got an email from SimpleMailer {{USERNAME}}. I hope you enjoyed how {{DIFFICULTY}} it was to do this.
Notice the {{USERNAME}} variable inside the HTML template. You'll be able to insert many of these variables in a simple array.
// 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/")
outVars := SimpleMailer.Variables{map[string]interface{}{"USERNAME":"gophers", "DIFFICULTY": "simple"}}
newOutgoing := SimpleMailer.Outgoing{
Email: "info@domain.com",
Subject: "SimpleMailer in Golang",
Template: "welcome.html",
Variables: outVars }
sendSuccess := SimpleMailer.SendSingle(newOutgoing)
fmt.Println(sendSuccess)
// outputs true or false
####### This will replace {{USERNAME}} in your HTML template to 'gophers'
var newOutgoing []SimpleMailer.Outgoing
outVars := SimpleMailer.Variables{map[string]interface{}{"USERNAME":"billy", "DIFFICULTY": "simple"}}
newOutgoingMessage := SimpleMailer.Outgoing{Email: "firstuser@domain.com", Subject: "Welcome Email", Template: "welcome.html", Variables: outVars}
newOutgoing = append(newOutgoing, newOutgoingMessage)
secondoutVars := SimpleMailer.Variables{map[string]interface{}{"USERNAME":"l33tguy", "DIFFICULTY": "super easy"}}
secondnewOutgoingMessage := SimpleMailer.Outgoing{Email: "firstuser@domain.com", Subject: "Welcome Email", Template: "welcome.html", Variables: secondoutVars}
newOutgoing = append(newOutgoing, secondnewOutgoingMessage)
// here is where you send multiple emails from a Outgoing array
responses := SimpleMailer.SendMultiple(newOutgoing)
for _,successSend := range responses {
userEmail := successSend["email"]
sentStatus := successSend["status"].(bool)
if sentStatus {
fmt.Println("Email to "+userEmail.(string)+" was successfully sent")
} else {
fmt.Println("ERROR - Email to "+userEmail.(string)+" was not able to send")
}
}
allEmails := []string{"info@emaildomain.com", "noreply@nodomain.com", "hey@gmail.com"}
bulkSend := SimpleMailer.BulkSend{Emails: allEmails, Subject: "Hello Bulk Sender", Template: "welcome.html"}
response := SimpleMailer.SendBulkEmails(bulkSend)
package main
import (
"github.com/hunterlong/simplemailer"
"fmt"
)
func main() {
SimpleMailer.SetSMTPInfo("emailserver-hidden.com", "465", "stmpusername", "passwordhere", "Sender Name", "info@sendfrom.com", "./emails/")
outVars := SimpleMailer.Variables{map[string]interface{}{"USERNAME":"gophers", "DIFFICULTY": "simple"}}
newOutgoing := SimpleMailer.Outgoing{
Email: "info@sendtoemail.com",
Subject: "SimpleMailer in Golang",
Template: "welcome.html",
Variables: outVars }
sendSuccess := SimpleMailer.SendSingle(newOutgoing)
fmt.Println(sendSuccess)
// outputs true if it was sent, false if error
}
SimpleMailer.SetSMTPInfo("smtp.gmail.com", "465", "<gmail email>", "<gmail password>", "Sender Name", "<gmail email>", "./emails/")
SimpleMailer.SetSMTPInfo("smtp.mail.yahoo.com", "465", "<yahoo email>", "<yahoo password>", "Sender Name", "<yahoo email>", "./emails/")
SimpleMailer.SetSMTPInfo("smtp.office365.com", "587", "<outlook email>", "<outlook password>", "Sender Name", "<outlook email>", "./emails/")
https://github.com/leemunroe/responsive-html-email-template
https://github.com/mailgun/transactional-email-templates
https://github.com/mailchimp/email-blueprints