我正在嘗試發送電子郵件gomail,需要設置發送電子郵件地址。我找到了設置回復地址的鏈接,該鏈接很接近,但不完全是我要找的。Send-as 是我知道 GMail 支持的功能,其他人也可能支持。我已經在 GMail 本身中配置了 send-as 并且工作正常,只是想看看我是否可以通過以下方式設置它gomail我嘗試了以下方法:通讀文檔gomailm.SetHeader("SendAs", emailAddress)m.SetHeader("Send-As", emailAddress)m.SetHeader("sendAs", emailAddress)m.SetAddressHeader("SendAs", emailAddress, "")m.SetAddressHeader("Send-As", emailAddress, "")m.SetAddressHeader("sendAs", emailAddress, "")func TestEmail(to, from, cc, bcc, subject, message, password, fileName string) (string, error) { // We need to parse the TO, CC, and BCC lists, which may contain more than one email address each. splitToField := strings.Split(to, ",") splitCCField := strings.Split(cc, ",") splitBCCField := strings.Split(bcc, ",") m := gomail.NewMessage() m.SetHeader("From", from) m.SetHeader("To", splitToField...) // If there is a CC address(s), then add them. if len(cc) > 0 { fmt.Println("CC LEN > 0", len(splitCCField)) m.SetHeader("Cc", splitCCField...) } // If there is a BCC address(s), then add them. if len(bcc) > 0 { fmt.Println("BCC LEN > 0", len(splitBCCField)) m.SetHeader("Bcc", splitBCCField...) } m.SetHeader("Subject", subject) m.SetBody("text/html", message) m.Attach("emailedQuotes/"+fileName) // So far, we configured this to ONLY work with GMail accounts. // Possibly in the future we can add an input on the front end and have them enter // their host/port manually. Or get fancy and parse the email address and have the most common // types in a struct. d := gomail.NewDialer("smtp.gmail.com", 587, from, password) err := d.DialAndSend(m) if err != nil { fmt.Println("ERROR SENDING EMAIL!", err) return "", err } else { fmt.Println("Email successfully sent to: ", to) return "Email successfully sent to:" + to, nil }}我的期望是您將能夠輸入地址的用戶名/密碼from,并能夠發送from地址顯示為send-as地址的郵件。如果我執行此操作(使用正確的地址用戶名/密碼from),它將正確發送電子郵件,但send-as不會接管from地址。所以,不起作用,但沒有錯誤。
1 回答

qq_笑_17
TA貢獻1818條經驗 獲得超7個贊
您鏈接的 google api 的文檔沒有談論設置 mime 標頭 - 據我所知沒有這樣的事情。因此在電子郵件上設置“SendAs”mime 標頭不會有任何效果。
您正在使用 gomail -它的github repo聲明“Gomail 只能使用 SMTP 服務器發送電子郵件” - 這意味著它沒有使用您鏈接的 api(與 mime 標頭無關)。
可能對您有用的只是將發件人地址設置為您已經在您的 google 帳戶上設置為發件人的地址,并使用 gomail 通過您的 google 帳戶發送。
- 1 回答
- 0 關注
- 217 瀏覽
添加回答
舉報
0/150
提交
取消