0

我使用 chilkat 9.5.0.80。

问题是电子邮件中的某些字符出现错误。例如,这在收件箱邮箱中è显示。è我希望它在我设置它时显示 - è

这是最小的可重现代码:

email := chilkat.NewEmail()
email.SetCharset("utf-8")
email.AddTo("", toEmail)
email.SetSubject("test")
email.SetHtmlBody("è")
mailMan := chilkat.NewMailMan()
mailMan.SetSmtpHost(host)
mailMan.SetSmtpPort(25)
mailMan.SetSmtpUsername(username)
mailMan.SetSmtpPassword(password)
mailMan.SendEmail(email)

我还注意到不同 smtp 服务器 mime 中的 html 正文部分的标头看起来不同。首先正确显示,如下所示:

--------------050209010604000502060206
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=iso-8859-1

第二个是错误的,看起来像:

--------------030709010607010008060507
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=utf-8

字符集不同..

我想如果我将 html 正文设置为 base64,它将显示正确。但是我在chilkat中没有发现这种可能性......

还尝试了有效的html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
è
</body>
</html>
4

1 回答 1

1

当我问到我的问题时,我是对的,如何使用 chilkat 将 html body 设置为 base64 ?因为以下代码在某些 smtp 服务器上正确显示特殊字符,但在某些服务器上却显示错误:

email := chilkat.NewEmail()
email.SetCharset("utf-8")
email.AddTo("", toEmail)
email.SetSubject("test")
email.SetHtmlBody("è")
mailMan := chilkat.NewMailMan()
mailMan.SetSmtpHost(host)
mailMan.SetSmtpPort(25)
mailMan.SetSmtpUsername(username)
mailMan.SetSmtpPassword(password)
mailMan.SendEmail(email)

下一个解决方案允许将 html body mime 部分设置和发送为 base64,它可以在不同的 smtp 服务器上正确显示:

email := chilkat.NewEmail()
part := chilkat.NewMime()
part.SetBodyFromEncoded("base64", 
base64.StdEncoding.EncodeToString([]byte(bodyContent)))
part.SetContentType("text/html")
part.SetCharset("UTF-8")
email.SetFromMimeText(*part.GetMime())

然后您可以将其他字段设置为email对象,例如主题等。

于 2020-07-21T09:55:56.373 回答