Skip to content

Instantly share code, notes, and snippets.

@m00zi
Forked from asit-dhal/simple_mail.go
Created October 23, 2018 07:09
Show Gist options
  • Save m00zi/cd0b18f8bd8d6802c0e212fd8874e053 to your computer and use it in GitHub Desktop.
Save m00zi/cd0b18f8bd8d6802c0e212fd8874e053 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("dhal.asitk@gmail.com")
c.Rcpt("asitdhal_tud@outloo.com")
// 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