gpt4 book ai didi

c# - 为什么 MailAddress 在有逗号时不引用 DisplayName?

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

我们最近从 .NET 2 迁移到了 .NET 4,System.Net.Mail.MailAddress 类让我很头疼。以前,如果我有电子邮件 (joe@example.com) 和显示名称(Joe Smith, CEO®),您可以:

MailAddress from = new MailAddress("joe@example.com", "Joe Smith, CEO®");

你会得到一个格式正确的 "Joe Smith, CEO" <joe@example.com>发送电子邮件时。这是可见的/可读的/等等。所有邮寄者。

在 .NET 4 中,Outlook/Exchange 对其编码方式进行了调整,将其拆分为逗号:<=?utf-8?Q?Joe@gwm.example.com>, CEO=C2=AE?= <joe@example.com>这导致它无法正确解码。

From Microsoft :

A comma is used to separate elements in a list of mail addresses. As a result, a comma should not be used in unquoted display names in a list.

这很好,但是当您这样做时:

MailAddress from = new MailAddress("joe@example.com", "\"Joe Smith, CEO®\"");

引号被删除是因为;

This method removes surrounding quotes not displayed by the DisplayName property.

那么您如何告诉 MailAddress 它不需要的逗号应该被引用,而不添加额外的空格(例如“\u200B\"Joe...\"")使邮件阅读器中的地址缩进?

更新

Microsoft 的回答(链接见回复评论):

Posted by Microsoft on 8/17/2011 -- Thank you for your feedback. This is a well known issue and a patch is currently being created for .NET 4.0. To obtain the patch please contact Microsoft Support directly regarding KB 2576045.

最佳答案

没有测试过,但是试试

 MailAddress from = new MailAddress("joe@nospam.com", "Joe Smith\",\" CEO®");

编辑 - 另一种选择:

 MailAddress from = new MailAddress("joe@nospam.com", "Joe Smith\x2C CEO®");

关于c# - 为什么 MailAddress 在有逗号时不引用 DisplayName?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7078122/

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