Last active
May 5, 2017 05:34
-
-
Save ARolek/5952925 to your computer and use it in GitHub Desktop.
A quick and dirty implementation of the Golang SMTP package used with GMail.
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 tools | |
import ( | |
"fmt" | |
"net/smtp" | |
) | |
var ( | |
username string = "" | |
password string = "" | |
host string = "smtp.gmail.com" | |
port string = "587" | |
) | |
func SendMail(to []string, subject string, msg string) error { | |
auth := smtp.PlainAuth( | |
"", | |
username, | |
password, | |
host, | |
) | |
address := fmt.Sprintf("%v:%v", host, port) | |
// build our message | |
body := []byte("Subject: " + subject + "\r\n\r\n" + msg) | |
err := smtp.SendMail( | |
address, | |
auth, | |
username, | |
to, | |
body, | |
) | |
if err != nil { | |
return err | |
} | |
return nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment