2 回答

TA貢獻1803條經(jīng)驗 獲得超3個贊
嘗試:在您的文本主題中使用此功能
func cSubject(subject string) string {
//return "=?iso-8859-1?Q?" + subject + "?="
return "=?utf-8?q?" + subject + "?="
}

TA貢獻1780條經(jīng)驗 獲得超1個贊
我使用 golang 使用以下代碼成功發(fā)送了 UTF8 電子郵件
func sendContactUs(name string, email string, userInput string) {
// Sender data.
from := "some@email.address"
password := "some password"
// Receiver email address.
to := []string{
"receipient@email.address",
}
// smtp server configuration.
smtpHost := "smtp.gmail.com"
smtpPort := "587"
raw := `Subject: {name} Contact form on Web
Content-Type: text/plain; charset="UTF-8"
Dear Manager,
We receive a a form submission from webpage
name : {name}
email : {email}
message:
{message}
Kind Regards
XXXX Mailing service team.
`
raw = strings.Replace(raw, "{name}", name, -1)
raw = strings.Replace(raw, "{email}", email, -1)
raw = strings.Replace(raw, "{message}", userInput, -1)
// Message.
message := []byte(raw)
// Authentication.
auth := smtp.PlainAuth("", from, password, smtpHost)
// Sending email.
err := smtp.SendMail(smtpHost+":"+smtpPort, auth, from, to, message)
if err != nil {
fmt.Println(err)
return
}
fmt.Println("Email Sent Successfully!")
}
請注意帶有Content-type 的行:它必須從頭開始。換句話說,它不應(yīng)該有任何前置空格。
此外,它后面必須有一個空行。
這是一個工作代碼。請試一試。如果您遇到任何問題,請告訴我。
- 2 回答
- 0 關(guān)注
- 189 瀏覽
添加回答
舉報