1588 shaares
88 liens privés
88 liens privés
package main
import (
"crypto/tls"
"fmt"
gomail "gopkg.in/mail.v2"
)
func main() {
m := gomail.NewMessage()
m.SetHeader("From", "youremail@gmail.com")
m.SetHeader("To", "recipient@example.com")
m.SetHeader("Subject", "Sending Email with Goalang")
// Set the email body. You can set plain text or html with text/html
m.SetBody("text/plain", "Hello World!")
// Settings for SMTP server
d := gomail.NewDialer("smtp.gmail.com", 587, "youremail@gmail.com", "yourpassword")
// This is only needed when the SSL/TLS certificate is not valid on the server.
// In production this should be set to false.
d.TLSConfig = &tls.Config{InsecureSkipVerify: true}
if err := d.DialAndSend(m); err != nil {
fmt.Println(err)
panic(err)
}
return
}