我在 Go 中为 SMTP 使用这个众所周知的空白画布。我需要在 Bcc Blank Carbon Copy 地址中添加它,但我已经尝试了很多东西,但我尝试的任何东西都不起作用,这很奇怪......我尝试添加 "headers["Bcc"] = "someemail@address.com" 我相信这是一个简单的修改。提前致谢..package mainimport ( "fmt" "log" "net" "net/mail" "net/smtp" "crypto/tls")func main() {from := mail.Address{"", "username@example.tld"}to := mail.Address{"", "username@anotherexample.tld"}subj := "This is the email subject"body := "This is an example body.\n With two lines."headers := make(map[string]string)headers["From"] = from.String()headers["To"] = to.String()headers["Subject"] = subjmessage := ""for k,v := range headers { message += fmt.Sprintf("%s: %s\r\n", k, v)}message += "\r\n" + bodyservername := "smtp.example.tld:465"host, _, _ := net.SplitHostPort(servername)auth := smtp.PlainAuth("","username@example.tld", "password", host)tlsconfig := &tls.Config { InsecureSkipVerify: true, ServerName: host,}conn, err := tls.Dial("tcp", servername, tlsconfig)if err != nil { log.Panic(err)}c, err := smtp.NewClient(conn, host)if err != nil { log.Panic(err)}if err = c.Auth(auth); err != nil { log.Panic(err)}if err = c.Mail(from.Address); err != nil { log.Panic(err)}if err = c.Rcpt(to.Address); err != nil { log.Panic(err)}w, err := c.Data()if err != nil { log.Panic(err)}_, err = w.Write([]byte(message))if err != nil { log.Panic(err)}err = w.Close()if err != nil { log.Panic(err)}c.Quit()
- 3 回答
- 0 关注
- 158 浏览
添加回答
举报
0/150
提交
取消