2 回答
TA贡献1803条经验 获得超3个赞
尝试:在您的文本主题中使用此功能
func cSubject(subject string) string {
//return "=?iso-8859-1?Q?" + subject + "?="
return "=?utf-8?q?" + subject + "?="
}
TA贡献1780条经验 获得超1个赞
我使用 golang 使用以下代码成功发送了 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 的行:它必须从头开始。换句话说,它不应该有任何前置空格。
此外,它后面必须有一个空行。
这是一个工作代码。请试一试。如果您遇到任何问题,请告诉我。
- 2 回答
- 0 关注
- 155 浏览
添加回答
举报