我正在使用net/smtp發(fā)送電子郵件,它似乎無法處理電子郵件中的聯(lián)系人姓名。c, _ := smtp.Dial("smtp.example.com:25")c.Mail(`jdoe@example.com`)而不是c, _ := smtp.Dial("smtp.example.com:25")c.Mail(`"John Q. Doe" <jdoe@example.com>`)有沒有好的辦法來處理這個問題?如果可用,我更喜歡封裝和標(biāo)準(zhǔn)的東西,但如果可以做到的話,我愿意使用原始 SMTP。
2 回答

波斯汪
TA貢獻(xiàn)1811條經(jīng)驗 獲得超4個贊
smtpServer := "smtp.example.com"
auth := smtp.PlainAuth("", "from@example.com", "******", smtpServer)
from := mail.Address{"fromName", "from@example.com"}
to := mail.Address{"toName", "to@example.com"}
msg := []byte("From: " + from.String() + "\r\n" +
"To: " + to.String() + "\r\n" +
"Subject: Awesome Subject !\r\n" +
"This is the email body.\r\n")
err := smtp.SendMail(smtpServer + ":25", auth, from.Address,[]string{to.Address}, msg)
if err != nil {
log.Fatal(err)
}
- 2 回答
- 0 關(guān)注
- 326 瀏覽
添加回答
舉報
0/150
提交
取消