发送国际化电子邮件

时间:2018-01-15 21:25:53

标签: c# sendgrid

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

支持

如果我从gmail的网络界面向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作为原因。

1 个答案:

答案 0 :(得分:0)

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

他们告诉我这是在他们的雷达,但没有时间承诺实施。