Golang net/smtp.SendMail() function example
package net/smtp
Golang net/smtp.SendMail() function usage example
// authentication configuration
smtpHost := "smtp.****" // change to your SMTP provider address
smtpPort := *** // change to your SMTP provider port number
smtpPass := "yourpassword" // change here
smtpUser := "yourusername@gmail.com" // change here
emailConf := &EmailConfig{smtpUser, smtpPass, smtpHost, smtpPort}
emailauth := smtp.PlainAuth("", emailConf.Username, emailConf.Password, emailConf.Host)
sender := "fromwho@gmail.com" // change here
receivers := []string{
"someone@somedomain.com",
"someone@somedomain.com"
} // change here
message := []byte("Hello from Go SMTP package!") // your message
// send out the email
err := smtp.SendMail(smtpHost+":"+strconv.Itoa(emailConf.Port), //convert port number from int to string
emailauth,
sender,
receivers,
message,
)
if err != nil {
fmt.Println(err)
}
See full example at https://www.socketloop.com/tutorials/golang-send-email-and-smtp-configuration-example
References :
http://golang.org/pkg/net/smtp/#SendMail
https://www.socketloop.com/tutorials/golang-send-email-and-smtp-configuration-example
Advertisement
Something interesting
Tutorials
+5.8k Golang : Launching your executable inside a console under Linux
+17k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+44.9k Golang : Use wildcard patterns with filepath.Glob() example
+10.5k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+5.6k Swift : Get substring with rangeOfString() function example
+32.5k Golang : Copy directory - including sub-directories and files
+14k Golang: Pad right or print ending(suffix) zero or spaces in fmt.Printf example
+6.7k Golang : When to use make or new?
+8.2k Golang : Reverse text lines or flip line order example
+8.2k Golang : Get final or effective URL with Request.URL example
+9.7k Golang : Find correlation coefficient example
+8.8k Golang : Gorilla web tool kit schema example