在名称中使用德语变音符号和逗号时,电子邮件接收器显示错误

发布于 2024-12-22 21:36:21 字数 2244 浏览 2 评论 0原文

使用 MailMessage 类< /a> 在 .NET 4 中,我今天发现了一个至今无法解决的问题。请参阅以下代码:

using (var message = new MailMessage())
{
    message.From = new MailAddress(@"[email protected]", "Uwe Keim");
    message.Bcc.Add(new MailAddress(@"[email protected]", "Uwe Keim"));

    // This fails (see screenshot).
    /*1*/ message.To.Add(new MailAddress(@"[email protected]", "Müller, Fred"));

    // This succeeds.
    /*2*/ message.To.Add(new MailAddress(@"[email protected]", "Fred Müller"));

    // This also succeeds.
    /*3*/ message.To.Add(new MailAddress(@"[email protected]", "Muller, Fred"));

    message.Subject = "Test";
    message.Body = "Some text body.";

    new SmtpClient().Send(message);
}

这是一个简单的代码片段,因此请发送一条 SMTP 消息。相互尝试 /*1*//*2*//*3*/ 行,行为会有所不同

: (“收件人”)名称包含德语变音符号(即“Ä”、“Ö”或“Ü”)逗号(即“,”),接收者会看到损坏的文本他收到的电子邮件

在此处输入图像描述

正如您在上面的屏幕截图(取自 Outlook 2010)中看到的,有一个神秘的“=?utf- “收件人:”行中的“8?Q?M=C3=BCller”。

省略逗号或删除德语元音变音可以解决此问题。我尝试了 Exchange 2003 和 hmailserver 以获得相同的结果。

我的问题是:

有人知道这种行为并有解决方案吗?

更新 1:

根据用户 Adam Maras 的建议,我启动了 Microsoft Network Monitor,同时发送电子邮件。

对我来说,似乎 MailMessage 类(或 SmtpClient 类?)已经做错了:

在此处输入图像描述

Using the MailMessage class in .NET 4, I found an issue today that I'm unable to resolve so far. Please see the following code:

using (var message = new MailMessage())
{
    message.From = new MailAddress(@"[email protected]", "Uwe Keim");
    message.Bcc.Add(new MailAddress(@"[email protected]", "Uwe Keim"));

    // This fails (see screenshot).
    /*1*/ message.To.Add(new MailAddress(@"[email protected]", "Müller, Fred"));

    // This succeeds.
    /*2*/ message.To.Add(new MailAddress(@"[email protected]", "Fred Müller"));

    // This also succeeds.
    /*3*/ message.To.Add(new MailAddress(@"[email protected]", "Muller, Fred"));

    message.Subject = "Test";
    message.Body = "Some text body.";

    new SmtpClient().Send(message);
}

This is a simple snippet so send an SMTP message. Mutually trying the lines /*1*/, /*2*/ and /*3*/, the behavior differs:

Whenever a receiver ("To") name contains a German umlaut (i.e. "Ä", "Ö" or "Ü") and a comma (i.e. ","), the receiver sees damaged text in the email message he receives:

enter image description here

As you can see in the above screenshot (taken from Outlook 2010), there is a cryptic "=?utf-8?Q?M=C3=BCller" in the "To:" line.

Leaving out the comma or removing the German umlaut fixes this. I've tried both Exchange 2003 and hmailserver to get the same result.

My question is:

Is anyone aware of this behaviour and has a solution to it?

Update 1:

As suggested by user Adam Maras, I fired up Microsoft Network Monitor while sending the email message.

To me, it seems that the MailMessage class (or the SmtpClient class?) is already doing it wrong:

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

那请放手 2024-12-29 21:36:21

因此,经过一番挖掘,我发现了 Microsoft 支持文章 2576045:修复:电子邮件客户端不支持 a 中的名称如果名称包含非 ASCII 字符,则由 .NET Framework 4 中的 MailMessage 类编码的投递地址字段。

看来,在写出包含 Unicode 字符的地址时,MailMessage 类未正确编码某些内容。我当然无法根据知识库文章的信息告诉你它是什么,但无论它是什么,都足以让下游读者被标题噎住。

So, after some digging, I came across Microsoft Support article 2576045: FIX: Email client does not support a name in a delivery address field that is encoded by the MailMessage class in the .NET Framework 4 if the name contains a non-ASCII character.

It appears that, when writing out an address that contains Unicode characters, the MailMessage class does not correctly encode something. I certainly can't tell you what it is based on the KB article's information, but whatever it is, it's enough to make downstream readers choke on the headers.

简美 2024-12-29 21:36:21

电子邮件标头必须为 us-ascii(7 位),使用变音符号需要按照 rfc2047 中所述进行编码。对字符串进行编码的方法有多种,看起来 Outlook 或您的邮件服务器无法理解 utf8 编码。

您可以尝试使用 iso-8859-1 自行对地址进行 mime 编码。

编辑:我刚刚检查了文档 http://msdn .microsoft.com/en-us/library/system.net.mail.mailaddress.aspx

您是否尝试过使用 MailAddress(String, String, Encoding) ?

E-mail headers have to be us-ascii (7-bit), using umlauts need encoding as discribed in rfc2047. There are different ways to encode the strings and it looks like outlook or your mailserver won't understand the utf8 encoding.

You could try to mime encode the address yourself using iso-8859-1.

edit: I just checked the documentation at http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx

have you tried using MailAddress(String, String, Encoding) ?

才能让你更想念 2024-12-29 21:36:21

我们实际上也遇到过类似的问题。主要是与主题有关。
MailMergeLib 是朝着正确方向迈出的一步:

http://www.codeproject.com/KB/ IP/MailMergeLib.aspx

您可以尝试一下,但它并不能解决我们所有的问题。现在我们切换到Aspose.Email。它更好了,但仍然不完美,我们仍然有乱码主题,但现在仅在 Mac 和 iPhone 上,但他们正在修复错误。

http://www.aspose.com /categories/.net-components/aspose.email-for-.net/default.aspx

您可以免费试用。网上还有其他电子邮件库。
http://www.chilkatsoft.com/products.asp

如果您弄清楚,我会非常感兴趣更多的东西。

We actually had similar issues. Mainly with the Subject though.
One step in the right direction was MailMergeLib:

http://www.codeproject.com/KB/IP/MailMergeLib.aspx

You could give that a try, but it didn't solve all our issues. Now we switched to Aspose.Email. It's better but still not perfect, we still have garbeled subject, but now only on Mac and iPhones, but they are working on a bugfix.

http://www.aspose.com/categories/.net-components/aspose.email-for-.net/default.aspx

You can try it for free. There are other email libraries on the net.
http://www.chilkatsoft.com/products.asp

Would be very intersted if you figure out something more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文