Skip to content

Instantly share code, notes, and snippets.

@schmitch
Created June 30, 2015 12:18
Show Gist options
  • Save schmitch/1571d2c15864202830ab to your computer and use it in GitHub Desktop.
Save schmitch/1571d2c15864202830ab to your computer and use it in GitHub Desktop.
// TLS config, do not set InsecureSkipVerify to true in production
// since it will accept all certificates
config := &tls.Config{
InsecureSkipVerify: false,
ServerName: host,
}
c, err := smtp.Dial(server)
if err != nil {
log.Fatal(err)
}
if err := c.StartTLS(config); err != nil {
log.Fatal(err)
}
if err := c.Auth(auth); err != nil {
log.Fatal(err)
}
if err := c.Mail(from.Address); err != nil {
log.Fatal(err)
}
if err = c.Rcpt(to.Address); err != nil {
log.Fatal(err)
}
w, err := c.Data()
if err != nil {
log.Fatal(err)
}
if _, err = w.Write([]byte(message)); err != nil {
log.Fatal("SMTP Write", err)
}
ret := c.Quit()
log.Println("Quit Message:", ret)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment