Skip to content

Instantly share code, notes, and snippets.

@ARolek
Last active May 5, 2017 05:34
Show Gist options
  • Save ARolek/5952925 to your computer and use it in GitHub Desktop.
Save ARolek/5952925 to your computer and use it in GitHub Desktop.
A quick and dirty implementation of the Golang SMTP package used with GMail.
package tools
import (
"fmt"
"net/smtp"
)
var (
username string = ""
password string = ""
host string = "smtp.gmail.com"
port string = "587"
)
func SendMail(to []string, subject string, msg string) error {
auth := smtp.PlainAuth(
"",
username,
password,
host,
)
address := fmt.Sprintf("%v:%v", host, port)
// build our message
body := []byte("Subject: " + subject + "\r\n\r\n" + msg)
err := smtp.SendMail(
address,
auth,
username,
to,
body,
)
if err != nil {
return err
}
return nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment