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)
}
}
/*
Don’t try this. This doesn’t work for Gmail. Gmail needs password for login and SSL/TLS for end-to-end security.
*/
-
Notifications
You must be signed in to change notification settings - Fork 0
go-project-action/smtpmail
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
2019.4.15_使用 Go 语言通过 SMTP 协议实现发送邮件功能
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published