亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Go Golang SMTP 腳本。需要添加密件抄送頭

Go Golang SMTP 腳本。需要添加密件抄送頭

Go
aluckdog 2023-06-01 17:00:34
我在 Go 中為 SMTP 使用這個眾所周知的空白畫布。我需要在 Bcc Blank Carbon Copy 地址中添加它,但我已經嘗試了很多東西,但我嘗試的任何東西都不起作用,這很奇怪......我嘗試添加 "headers["Bcc"] = "[email protected]" 我相信這是一個簡單的修改。提前致謝..package mainimport (   "fmt"   "log"   "net"   "net/mail"   "net/smtp"   "crypto/tls")func main() {from := mail.Address{"", "[email protected]"}to   := mail.Address{"", "[email protected]"}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("","[email protected]", "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 回答

?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

請參閱smtp#SendMail 包文檔中的以下部分

msg 參數應該是一個 RFC 822 風格的電子郵件,首先是標題,一個空行,然后是郵件正文。msg 行應該以 CRLF 終止。消息標頭通常應包括“發件人”、“收件人”、“主題”和“抄送”等字段。發送“密件抄送”消息是通過在 to 參數中包含電子郵件地址但不將其包含在消息標頭中來完成的。

換句話說,不要將它們添加到標題中,而只是添加到收件人列表中。

在您的示例樣板代碼中,您將為密件抄送列表中的每封電子郵件添加一個調用c.Rcpt(...),僅此而已。沒有什么可以添加到標題中。


查看完整回答
反對 回復 2023-06-01
?
當年話下

TA貢獻1890條經驗 獲得超9個贊

您還需要RCPT為 Bcc 地址添加一行,例如:

if err = c.Rcpt("[email protected]"); err != nil {
    log.Panic(err)
}


查看完整回答
反對 回復 2023-06-01
?
小怪獸愛吃肉

TA貢獻1852條經驗 獲得超1個贊

該標準不包括抄送的概念。您需要為每個收件人添加一個 RCPT TO,然后將 bcc: [email protected] 添加到正文。客戶將負責其余的工作。



查看完整回答
反對 回復 2023-06-01
  • 3 回答
  • 0 關注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號