Skip to content

Instantly share code, notes, and snippets.

@marclambrichs
Created September 18, 2017 06:09
Show Gist options
  • Save marclambrichs/d46ff6278c62d480ee0c2d77f86b74f3 to your computer and use it in GitHub Desktop.
Save marclambrichs/d46ff6278c62d480ee0c2d77f86b74f3 to your computer and use it in GitHub Desktop.
go net/smtp example
package main
import (
"log"
"net/smtp"
)
func main() {
hostname := "smtp.gmail.com"
from := "me@gmail.com"
to := []string{"you@gmail.com"}
msg := []byte("To: you@gmail.com\r\n" +
"Subject: Testing\r\n" +
"\r\n" +
"This is the email body.\r\n")
// build an auth
auth := smtp.PlainAuth("", from, "******", hostname)
err := smtp.SendMail(hostname+":587", auth, from, to, msg)
if err != nil {
log.Fatal(err)
}
log.Println("Mail sent successfully")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment