Created
June 30, 2015 12:18
-
-
Save schmitch/1571d2c15864202830ab to your computer and use it in GitHub Desktop.
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
// 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