Skip to content

Instantly share code, notes, and snippets.

@akovardin
Forked from jpillora/smtp-gmail-send.go
Last active February 18, 2019 10:02
Show Gist options
  • Save akovardin/cc64117e1d2d25828d9f to your computer and use it in GitHub Desktop.
Save akovardin/cc64117e1d2d25828d9f to your computer and use it in GitHub Desktop.
Send email using Go via GMail
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")
}
@surabhivyas
Copy link

giving password in the code wont make it vulnerable to hacking? I mean there wont be any security threats for the senders account? Kindly reply as I am also trying to create similar kind of application for a group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment