Skip to content

Instantly share code, notes, and snippets.

@meain
Created December 22, 2017 03:22
Show Gist options
  • Save meain/4de40467b7ca2784a90c025c548706f7 to your computer and use it in GitHub Desktop.
Save meain/4de40467b7ca2784a90c025c548706f7 to your computer and use it in GitHub Desktop.
package main
import (
"log"
"net/smtp"
)
func main() {
send("hello there")
}
func send(body string) {
from := "[email protected]"
pass := "password"
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 the galaxy far far away")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment