简体   繁体   English

System.Net.Mail.MailAddress'解析器接受的格式是什么?

[英]What is the format accepted by System.Net.Mail.MailAddress' parser?

I'm working on an app that's using System.Net.Mail.MailAddress and friends for sending emails. 我正在使用一个使用System.Net.Mail.MailAddress和朋友发送电子邮件的应用程序。 Does that parser implement the full RFC5322 or a subset or what? 该解析器是实现完整的RFC5322还是子集或什么? The MSDN is not very forthcoming on this topic. 关于这个话题,MSDN并不是很乐意。

Any hints appreciated. 任何提示赞赏。

I've wrote a little snippet to test the function: 我写了一个小片段来测试函数:

foreach (int i in Enumerable.Range(32,128-32))
{
    char c = (char)i;
    string addr = String.Format("par.t1{0}pa.r{0}t2@example.com", c);
    try
    {
        var mailAddr = new MailAddress(addr);
    }
    catch
    {
        Console.WriteLine("MailAddress failed '{0}' ({1}): {2}", c, i, addr);
    }
}

With the following results on 3.5 SP1: 在3.5 SP1上有以下结果:

MailAddress failed ' ' (32): par.t1 pa.r t2@example.com
MailAddress failed '"' (34): par.t1"pa.r"t2@example.com
MailAddress failed '(' (40): par.t1(pa.r(t2@example.com
MailAddress failed ')' (41): par.t1)pa.r)t2@example.com
MailAddress failed ',' (44): par.t1,pa.r,t2@example.com
MailAddress failed ':' (58): par.t1:pa.r:t2@example.com
MailAddress failed ';' (59): par.t1;pa.r;t2@example.com
MailAddress failed '<' (60): par.t1<pa.r<t2@example.com
MailAddress failed '>' (62): par.t1>pa.r>t2@example.com
MailAddress failed '@' (64): par.t1@pa.r@t2@example.com
MailAddress failed '[' (91): par.t1[pa.r[t2@example.com
MailAddress failed '\' (92): par.t1\pa.r\t2@example.com
MailAddress failed ']' (93): par.t1]pa.r]t2@example.com
MailAddress failed '⌂' (127): par.t1⌂pa.r⌂t2@example.com

Also it doesn't seem to support "quoted-string" local-parts, like "blah"@example.com . 此外,它似乎不支持“quoted-string”本地部分,如“ "blah"@example.com

I don't think a validator could accept any less before becoming unusable. 我认为验证者在变得无法使用之前不会接受任何更少的验证。

In the discussion thread on Dominic Sayers isemail article , Jerry O'Brien said that he read Dominic's RFC compliance test cases against the System.Net.MailAddress class: 在关于Dominic Sayers isemail文章的讨论主题中,Jerry O'Brien说他阅读了针对System.Net.MailAddress类的Dominic的RFC兼容性测试案例:

System.Net.MailAddress is only 59% compliant with the RFC specifications. System.Net.MailAddress仅符合RFC规范59%。 Follow-up comments noted the specific cases where it generated false positives and false negatives. 后续评论指出了产生误报和漏报的具体情况。

The RFCs are extremely weak on what constitutes a valid email email address. RFC对于有效的电子邮件地址构成极其微弱。 They allow a range of unusual and unpopular formats. 它们允许一系列不寻常和不受欢迎的格式。 So I guess the real question is, is System.Net.MailAddress good enough in a majority of real-world situations? 所以我想真正的问题是, System.Net.MailAddress在大多数现实情况下是否足够好?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Net.Mail.MailAddress使用一个参数发送到多封电子邮件 - System.Net.Mail.MailAddress send to multiple emails with one parameter 我应该在域模型中使用System.Net.Mail.MailAddress还是仅使用字符串? - Should I use System.Net.Mail.MailAddress in my domain model, or just strings? 为什么 System.Net.Mail.MailAddress 构造函数在域部分解析带有斜杠“/”的电子邮件? - Why System.Net.Mail.MailAddress constructor parses email with slash "/" in domain part? .NET中的MailAddress - MailAddress in .NET 创建新的MailAddress会产生“指定的字符串不是电子邮件地址所需的格式”,尽管它的格式正确 - Creating a new MailAddress produces “The specified string is not in the form required for an e-mail address”, although it is in the correct format 从用户输入文本中提取(多个)电子邮件到MailAddress格式(.NET) - Extract (multiple) emails from user-input text into the MailAddress format (.NET) MailAddress:在邮件头中找到无效字符 - MailAddress: An invalid character was found in the mail header 使用System.Net.Mail发送邮件 - Send mail with System.Net.Mail 使用{System.Net.Mail}发送邮件 - Sending mail using { System.Net.Mail } .net:System.Web.Mail与System.Net.Mail - .net: System.Web.Mail vs System.Net.Mail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM