Skip to content

Instantly share code, notes, and snippets.

@asit-dhal
Created September 26, 2016 05:42
Show Gist options
  • Save asit-dhal/458bbdcb471babe14f71b3f8f3938313 to your computer and use it in GitHub Desktop.
Save asit-dhal/458bbdcb471babe14f71b3f8f3938313 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"log"
"net/smtp"
)
func main() {
// Connect to the remote SMTP server.
c, err := smtp.Dial("smtp.gmail.com:465")
if err != nil {
log.Fatal(err)
}
defer c.Close()
// Set the sender and recipient.
c.Mail("[email protected]")
c.Rcpt("[email protected]")
// Send the email body.
wc, err := c.Data()
if err != nil {
log.Fatal(err)
}
defer wc.Close()
buf := bytes.NewBufferString("This is the email body.")
if _, err = buf.WriteTo(wc); err != nil {
log.Fatal(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment