Skip to content

Instantly share code, notes, and snippets.

@fhpriamo
Forked from jpillora/smtp-gmail-send.go
Created March 27, 2017 22:18
Show Gist options
  • Save fhpriamo/b3b95f854b5a7242e9cc156823ab5923 to your computer and use it in GitHub Desktop.
Save fhpriamo/b3b95f854b5a7242e9cc156823ab5923 to your computer and use it in GitHub Desktop.
Send email using Go (Golang) via GMail with net/smtp
package main
import (
"log"
"net/smtp"
)
func main() {
send("hello there")
}
func send(body string) {
from := "[email protected]"
pass := "..."
to := "[email protected]"
msg := "From: " + from + "\n" +
"To: " + to + "\n" +
"Subject: Hello there\n\n" +
body
err := smtp.SendMail("smtp.gmail.com:587",
smtp.PlainAuth("", from, pass, "smtp.gmail.com"),
from, []string{to}, []byte(msg))
if err != nil {
log.Printf("smtp error: %s", err)
return
}
log.Print("sent, visit http://foobarbazz.mailinator.com")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment