从rfc5321,第 2.3.5 节:
A domain name (or often just a "domain") consists of one or more
components, separated by dots if more than one appears. In the case
of a top-level domain used by itself in an email address, a single
string is used without any dots. This makes the requirement,
described in more detail below, that only fully-qualified domain
names appear in SMTP transactions on the public Internet,
particularly important where top-level domains are involved. These
components ("labels" in DNS terminology, RFC 1035 [2]) are restricted
for SMTP purposes to consist of a sequence of letters, digits, and
hyphens drawn from the ASCII character set [6]. Domain names are
used as names of hosts and of other entities in the domain name
hierarchy. For example, a domain may refer to an alias (label of a
CNAME RR) or the label of Mail eXchanger records to be used to
deliver mail instead of representing a host name. See RFC 1035 [2]
and Section 5 of this specification.
换句话说,一个域abc.def.xyz
由 3 个组件(又名标签)组成:abc
、def
和xyz
。这些标签中的每一个都只允许包含字母、数字和连字符。对于更具体的定义,我们必须检查命令参数语法部分中的 ABNF 语法,因为我们真正关心的是MAIL FROM
和RCPT TO
命令的参数语法(也就是外行术语中的“电子邮件地址”标记)。
Mailbox
在 SMTP 规范中,“电子邮件地址”实际上被称为:
Mailbox = Local-part "@" ( Domain / address-literal )
现在来看看Local-part
令牌的定义:
Local-part = Dot-string / Quoted-string
; MAY be case-sensitive
Dot-string = Atom *("." Atom)
Atom = 1*atext
要得到它的定义atext
,我们需要看一下Internet Message Format。具体来说,我们需要看第 3.2.3 节:
atext = ALPHA / DIGIT / ; Printable US-ASCII
"!" / "#" / ; characters not including
"$" / "%" / ; specials. Used for atoms.
"&" / "'" /
"*" / "+" /
"-" / "/" /
"=" / "?" /
"^" / "_" /
"`" / "{" /
"|" / "}" /
"~"
(注意:我省略了 a 的定义,Quoted-string
因为它与您的问题无关。)
现在让我们看看 a 的定义Domain
:
Domain = sub-domain *("." sub-domain)
sub-domain = Let-dig [Ldh-str]
Let-dig = ALPHA / DIGIT
Ldh-str = *( ALPHA / DIGIT / "-" ) Let-dig
我们在这里看到的是标签与标记相同sub-domain
,但在这里我们还看到 a 的标签(又名sub-domain
)Domain
不能以连字符开头或结尾。
我们还可以看到,sub-domain
标记实际上是 an 中允许的字符的子集,Atom
因此 a 的每个组件中允许的字符与 a的每个组件中允许的字符Local-part
不同。Domain
要回答您的其他问题:
有了这个,其中哪些是有效的电子邮件地址(如果有的话)?
-bobross@painting.com [VALID]
bobross-@painting.com [VALID]
bobross@-painting.com [INVALID]
bobross@painting-.com [INVALID]
我的理解是标签既不能以连字符结尾也不能以连字符开头,并且不能包含两个连续的连字符。我错过了什么吗?
让我们用这个词sub-domain
来让事情变得不那么混乱。
对,那是正确的。
加分 - 本地部分允许使用许多特殊字符,但我看到的一些消息来源说本地部分必须以字母数字字符结尾,但我实际上并没有在任何标准中看到这一点。我错过了它还是可以以允许的字符之一结尾?
那么,根据 rfc5322 的 ABNF 语法,aLocal-part
既可以以连字符开头也可以以连字符结尾。