gpt4 book ai didi

c# - 在 C# 中使用 X-SMTPAPI 发送网格字符编码 header

转载 作者:太空狗 更新时间:2023-10-29 21:54:46 29 4
gpt4 key购买 nike

我正在使用 SendGridPlus API用于使用 SendGrid 发送电子邮件。一切正常。但是当我将它们包含在 header 的替换值中时,我遇到了诸如 áé 之类的西类牙字符问题。

例如,如果我包含 Que día más bueno hace,我会收到 Que día más bueno hace

代码如下:

       [Test]
public void TestSendGrid()
{
//create a new message object
var message = Mail.GetInstance();
var recipients = new List<string>();

//You could loop through your dataset here and add each recipient, up to 1000 recipients per message
recipients.Add("juanp_perez@loyaltycrm.com");
recipients.Add("juanp_perez@msn.com");

//We want to add the recipients to the X-SMTPAPI header
message.Header.AddTo(recipients);

//Even though we added recipients to the Header, the envelope must also have a valid recipient
message.AddTo("juanp_perez@loyaltycrm.com");

//set the sender
message.From = new MailAddress(From);

//set the message body
message.Html = "<html><p>Hello *|USERNAME|*</p><p>World *|MESSAGE|* </p></html>";


//This replacement key must exist in the message body
var replacementKey = "*|USERNAME|*";

//There should be one value for each recipient in the To list
var substitutionValues = new List<string> { "Mr Foo", "Mrs Raz" };

message.AddSubVal(replacementKey, substitutionValues);

//This replacement key must exist in the message body
replacementKey = "*|MESSAGE|*";

//There should be one value for each recipient in the To list
substitutionValues = new List<string> { "Que día más bueno hace", "ea4t1qj8BnU%3d" };

message.AddSubVal(replacementKey, substitutionValues);

//set the message subject
message.Subject = "Hello World HTML Test";

//create an instance of the SMTP transport mechanism
var transportInstance = SMTP.GetInstance(new NetworkCredential(Username, Password));

//send the mail
transportInstance.Deliver(message);
}

有人可以就如何避免这种情况提供建议吗?

这是使用 unicode 字符后的电子邮件标题。

> Delivered-To: juanp_perez@loyaltycrm.com Received: by 10.194.13.129
> with SMTP id h1csp46752wjc;
> Fri, 14 Dec 2012 13:49:55 -0800 (PST) Received: by 10.182.89.103 with SMTP id bn7mr5984026obb.35.1355521795301;
> Fri, 14 Dec 2012 13:49:55 -0800 (PST) Return-Path: <bounces+50334-7e69-juanp_perez=loyaltycrm.com@email.loyaltycrm.com>
> Received: from o1.email.loyaltycrm.com (o1.email.loyaltycrm.com.
> [208.117.60.213])
> by mx.google.com with SMTP id kq7si6188156obb.180.2012.12.14.13.49.54;
> Fri, 14 Dec 2012 13:49:55 -0800 (PST) Received-SPF: pass (google.com: domain of
> bounces+50334-7e69-juanp_perez=loyaltycrm.com@email.loyaltycrm.com
> designates 208.117.60.213 as permitted sender)
> client-ip=208.117.60.213; Authentication-Results: mx.google.com;
> spf=pass (google.com: domain of
> bounces+50334-7e69-juanp_perez=loyaltycrm.com@email.loyaltycrm.com
> designates 208.117.60.213 as permitted sender)
> smtp.mail=bounces+50334-7e69-juanp_perez=loyaltycrm.com@email.loyaltycrm.com;
> dkim=pass header.i=@sendgrid.info DKIM-Signature: v=1; a=rsa-sha1;
> c=relaxed; d=sendgrid.info; h=
> mime-version:from:to:subject:content-type
> :content-transfer-encoding; s=smtpapi; bh=VEWUIUwwWzV7+YxR73tT5c
> ppXfY=; b=bccVTLSqyIp8og5+IMAAwcZk54FnLw8k38X9/rNwRqVUTgj+CZQDwD
> LOujhu+HDnYfZXOf78dugxcg5ScWNiDzbuEh6vr3xy9jNEiwkL+yiplayfWeXwGx
> r63P7qXjhADkfn/nDeca5QkMN08Pf3+4XFWTJiRHqG0T2hGOjwxZM=
> DomainKey-Signature: a=rsa-sha1; c=nofws; d=loyaltycrm.com; h=
> mime-version:from:to:subject:content-type
> :content-transfer-encoding; q=dns; s=smtpapi; b=PC8I8GCSsZbqJBBW
> i3mz2jhVy2lxTUqqinzsTu/GMl725muTRKS32KpQioE6iHIMm1thHbtrFP19DSiq
> edJhQ5BKfCNZKrxT72c9DS1/lSl96euCqEsIbHA3b/PWl7OxgoVCw3FdOGljssh7
> lQQLGeBIh3HbYo1yL1huXbG72Js= Received: by 10.4.35.208 with SMTP id
> mf73.16152.50CB9EF79
> Fri, 14 Dec 2012 15:49:43 -0600 (CST) Received: from LCRM1 (unknown [10.60.208.13]) by None (SG) with ESMTP id
> 50cb9ef7.7fc9.381e109 for <juanp_perez@loyaltycrm.com>; Fri, 14 Dec
> 2012 15:49:43 -0600 (CST) MIME-Version: 1.0 From: info@loyaltycrm.com
> To: juanp_perez@loyaltycrm.com Date: 14 Dec 2012 22:49:40 +0100
> Subject: Hello World HTML Test Content-Type: text/html;
> charset=us-ascii Content-Transfer-Encoding: quoted-printable
> Message-ID: <1355521783.554221818170987@mf73.sendgrid.net>
> X-Sendgrid-EID:
> gCyESDQLdMYAVtS85w9Vrx3WCa1D47LsR1aGBtau8RBzc10shTwXzozJNPYySyl9DqFygFiq8Fky1nQzp1S/n1d/BrVpf0HPjWlFU0UghfqTLmqRf+7tZknCIg1mkVq0


<html><p>Hello Mr Foo</p><p>World Que d\u00EDa m\u00E1s bueno hace </p></html>

<img src=3D"http://email.loyaltycrm.com/wf/open?upn=3DAMeQx0pEtkpR4-2FebJhh=
IV-2FlVQNg-2BgGs-2FqnbUO1ME7JjAjdPdI5TbxawOrUSlu-2B8QnxtPMS9mOdHRwby4N4j1B1=
YJZARjusRG5pNHPBQW6tTE0gcAX6G4HdYpZXXrySEYSn5w-2FxuNG1Wm3UUoOOwRFH-2FxLn2CF=
F4MD17CYSTJ6biVBbVijCX7rKc9RM-2FIErLm" alt=3D"" width=3D"1" height=3D"1" bo=
rder=3D"0" style=3D"height:1px !important;width:1px !important;border-width=
:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-rig=
ht:0 !important;margin-left:0 !important;padding-top:0 !important;padding-b=
ottom:0 !important;padding-right:0 !important;padding-left:0 !important;"/>

最佳答案

默认情况下(和 RFC)SMTP header 是 US-ASCII。为了发送非 ASCII 字符,您需要使用 Unicode 转义序列。我使用了以下字符串并且它起作用了。

Que d\u00EDa m\u00E1s bueno hace

您可以在 C# 中找到一个函数来自动为您转义这些字符:Convert a Unicode string to an escaped ASCII string

关于c# - 在 C# 中使用 X-SMTPAPI 发送网格字符编码 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13873772/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com