Created
September 26, 2016 05:42
-
-
Save asit-dhal/458bbdcb471babe14f71b3f8f3938313 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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