Skip to content

Instantly share code, notes, and snippets.

@dasgoll
Forked from jpillora/smtp-gmail-send.go
Created October 8, 2020 19:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dasgoll/494e1c4d2d7d20ea84ae180301b30ad2 to your computer and use it in GitHub Desktop.
Save dasgoll/494e1c4d2d7d20ea84ae180301b30ad2 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 := "...@gmail.com"
pass := "..."
to := "foobarbazz@mailinator.com"
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