package main import ( "fmt" "log" "net/smtp" ) const ( SMTP_SERVER = "smtp.gmail.com" SMTP_PORT = 587 ) func send(from, pass, to, subject, body string) error { msg := fmt.Sprintf("From: %s\nTo: %s\nSubject: %s\n\n%s", from, to, subject, body) auth := smtp.PlainAuth("", from, pass, SMTP_SERVER) return smtp.SendMail(fmt.Sprintf("%s:%d", SMTP_SERVER, SMTP_PORT), auth, from, []string{to}, []byte(msg)) } func main() { from := "abc@gmail.com" pass := "secret_password" to := "xyz@gmail.com" subject := "Hi there" body := "This is body" if err := send(from, pass, to, subject, body); err != nil { log.Fatal(err) } log.Println("Done") }