gpt4 book ai didi

c# - 发送国际化电子邮件

转载 作者:行者123 更新时间:2023-11-30 17:31:13 26 4
gpt4 key购买 nike

如何发送带有重音字母的电子邮件?示例是 pepé@lefrenchplace.com,现在应该支持 RFC 6532

如果我从 gmail 的 Web 界面向 pepé@lefrenchplace.com 发送电子邮件,它会毫无问题地送达。

我正在使用 .NET 4.6.1C#SendGrid

首次尝试使用 SMTP:

var smtp = new SmtpClient(Server)
{
Credentials = new NetworkCredential(Username, ApiKey),
DeliveryFormat = SmtpDeliveryFormat.International
};

var message = new MailMessage(From, To)
{
Subject = Subjet,
Body = BodyPlainText
};

smtp.Send(message);

这将抛出一个 SmtpException 消息 The client or server is only configured for E-mail addresses with ASCII local-parts: pepé@lefrenchplace.com.

第二次尝试 API V3 with SendGrid C# library

var apiKey = Environment.GetEnvironmentVariable("NAME_OF_THE_ENVIRONMENT_VARIABLE_FOR_YOUR_SENDGRID_KEY");
var client = new SendGridClient(apiKey);
var from = new EmailAddress("test@example.com", "Example User");
var subject = "Sending with SendGrid is Fun";
var to = new EmailAddress("pepé@lefrenchplace.com", "Example User");
var plainTextContent = "and easy to do anywhere, even with C#";
var htmlContent = "<strong>and easy to do anywhere, even with C#</strong>";
var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
var response = await client.SendEmailAsync(msg);

我收到返回的 Accepted 状态代码。在 SendGrid 仪表板上,它显示为 Dropped with Invalid 作为原因。

最佳答案

编辑 2020 年 8 月

SendGrid 已关闭 Github 问题。任何想要符合标准的电子邮件提供商发送到国际化电子邮件地址的人都应该去别处看看。 Mailgun会工作


截至目前,SendGrid 根本不支持具有非 ASCII 本地部分的电子邮件地址。

他们告诉我它在他们的雷达上,但没有时间 promise 实现。

Github issue

关于c# - 发送国际化电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48270879/

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