smtp

 

2022-11-23

1
package main
2
3
import (
4
"log"
5
"net/smtp"
6
)
7
8
var (
10
// To From Subject 非必须
11
msg = []byte("To:[email protected]\r\n" +
12
"From: [email protected]\r\n" +
13
"Subject: Hello World\r\n" +
14
"\r\n" +
15
"这是测试邮件\n\r")
16
recipients = []string{"[email protected]"}
17
)
18
19
func main() {
20
hostname := "smtp.exmail.qq.com"
21
auth := smtp.PlainAuth("", "[email protected]", "password", hostname)
22
23
err := smtp.SendMail(hostname+":25", auth, from, recipients, msg)
24
if err != nil {
25
log.Fatal(err)
26
}
27
}