简体   繁体   English

为什么 System.Net.Mail.MailAddress 构造函数在域部分解析带有斜杠“/”的电子邮件?

[英]Why System.Net.Mail.MailAddress constructor parses email with slash "/" in domain part?

We have following code:我们有以下代码:

using System;
using System.Net.Mail;

public class Program
{
    public static void Main()
    {
        var mailAddress = new MailAddress("username@domain/domain.com");    // Doesn't throw FormatException
        Console.WriteLine(mailAddress.Host);                                // Prints "domain/domain.com"
    }
}

We expect MailAddress constructor to throw FormatException because "/" is not supported in domain name.我们希望 MailAddress 构造函数抛出 FormatException,因为域名不支持“/”。 Is there reason why MailAddress parses them? MailAddress 是否有理由解析它们?

.NET uses RFC 2822 standart for its validation process of e-mail addresses. .NET 使用RFC 2822标准进行电子邮件地址验证过程。

According to document forward slash ( / ) is a valid character for domain part.根据文档,正斜杠( / ) 是域部分的有效字符。

Please see address specification at RFC 2822 3.4.1 :请参阅RFC 2822 3.4.1 中的地址规范

addr-spec       =       local-part "@" domain

local-part      =       dot-atom / quoted-string / obs-local-part

domain          =       dot-atom / domain-literal / obs-domain

domain-literal  =       [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS]

dcontent        =       dtext / quoted-pair

dtext           =       NO-WS-CTL /     ; Non white space controls

                        %d33-90 /       ; The rest of the US-ASCII
                        %d94-126        ;  characters not including "[",
                                        ;  "]", or "\"

Domain can be dot-atom which is described at RFC 2822 3.2.4 :域可以是RFC 2822 3.2.4 中描述的点原子

atext           =       ALPHA / DIGIT / ; Any character except controls,
                        "!" / "#" /     ;  SP, and specials.
                        "$" / "%" /     ;  Used for atoms
                        "&" / "'" /
                        "*" / "+" /
                        "-" / "/" /
                        "=" / "?" /
                        "^" / "_" /
                        "`" / "{" /
                        "|" / "}" /
                        "~"

atom            =       [CFWS] 1*atext [CFWS]

dot-atom        =       [CFWS] dot-atom-text [CFWS]

dot-atom-text   =       1*atext *("." 1*atext)

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

相关问题 RegEx由System.Net.Mail.MailAddress使用 - Is RegEx used by System.Net.Mail.MailAddress System.Net.Mail.MailAddress验证电子邮件缺少TLD,认为我@有效 - System.Net.Mail.MailAddress validates email missing TLD, considers me@there valid 无法将System.Net.Mail.MailAddress序列化为Json - Unable to serialize System.Net.Mail.MailAddress to Json System.Net.Mail.MailAddress使用一个参数发送到多封电子邮件 - System.Net.Mail.MailAddress send to multiple emails with one parameter System.Net.Mail.MailAddress不允许Gmail GROUP联系人 - System.Net.Mail.MailAddress does not allow Gmail GROUP contact 无法将类型“System.Net.Mail.MailAddress”隐式转换为“SendGrid.Helpers.Mail.EmailAddress” - Cannot implicitly convert type 'System.Net.Mail.MailAddress' to 'SendGrid.Helpers.Mail.EmailAddress' 使用System.Net.Mail.MailAddress或其他库指定.eml文件名 - Specify .eml file name using System.Net.Mail.MailAddress or other library MailAddress构造函数如何验证邮件地址 - How does the MailAddress constructor validate mail addresses 为什么System.Net.Mail可以在我的c#.net Web应用程序的一部分中工作,而不能在另一部分工作? - Why does System.Net.Mail work in one part of my c#.net web app, but not in another? asp email System.Net.Mail - asp email System.Net.Mail
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM