Created
September 18, 2017 06:09
-
-
Save marclambrichs/d46ff6278c62d480ee0c2d77f86b74f3 to your computer and use it in GitHub Desktop.
go net/smtp example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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