I've been reading through RFC, summaries, wikipedia, etc. I'm super confused about local-part vs labels. It seems to me that the local-part is before the @. That much seems straightforward. The label is any part of the domain separated by a dot. But it seems to me that some places also refer to the local-part as a label. And that is very confusing within the context of where hyphens are allowed. So specifically what is a label?
And with that, which of these are valid email address (if any)?
[email protected]
[email protected]
[email protected]
[email protected]
My understanding is that a label can neither end or begin with a hyphen and it must not contain two consecutive hyphens. Am I missing anything with that?
Bonus points - there are a number of special characters allowed in the local-part, but some sources I've seen say that the local-part must end in an alphanumeric character, but I'm not actually seeing that in any standard..am I missing it or can it end with one of the allowed characters?
From rfc5321, section 2.3.5:
In other words, a domain of
abc.def.xyzis made up of 3 components (aka labels):abc,def, andxyz. Each of these labels is only allowed to contain letters, digits, and hyphens. For a more specific definition, we must check the ABNF grammar in the Command Argument Syntax section because what we really care about is the syntax of the arguments to theMAIL FROMandRCPT TOcommands (aka the "email address" tokens in layman's terms).An "email address" is actually referred to as a
Mailboxin the SMTP specification:Now to look at the definition of a
Local-parttoken:To get the definition of
atext, we need to look at the Internet Message Format. Specifically, we need to look at section 3.2.3:(Note: I've left out the definition of a
Quoted-stringbecause it's irrelevant to your question.)Now let's check out the definition of a
Domain:What we see here is that a label is the same thing as a
sub-domaintoken, but here we also see that labels (akasub-domain's) of aDomaincannot start or end with a hyphen.We can also see that a
sub-domaintoken is actually a subset of the allowable characters in anAtomand so the characters allowed in each component of aLocal-partare not the same as those allowed in each component of aDomain.To answer your other questions:
Let's use the term
sub-domainto make things less confusing.Yes, that is correct.
Well, according to the ABNF grammar of rfc5322, a
Local-partcan both start and end with a hyphen.