コード日進月歩

しんくうの技術的な小話、メモ、つれづれ、など

2022年時点のメールアドレスの最大長は色々な仕様を鑑みると254文字

メールアドレスって最長どれくらいなの?という問いに対するひとつの指針。

先にまとめ

  • メールアドレスのフォーマットだけの仕様を取り上げると64+254=318文字が最大長と解釈できる。
  • ただし、SMTPの仕様で送り先を指定するforward-pathが256文字という定義もある。
    • そちらに加えてDNSの名前解決の仕様上、メールアドレスに合わせて最初と最後に区切り文字列を付与する必要があるため、実質254文字が限界

RFC5321(SMTP)の仕様

アドレス自体の定義

まずはメールアドレスの構成要素に関する定義だが、こちらはRFC5321に以下の記述がある。

As used in this specification, an "address" is a character string that identifies a user to whom mail will be sent or a location into which mail will be deposited. The term "mailbox" refers to that depository. The two terms are typically used interchangeably unless the distinction between the location in which mail is placed (the mailbox) and a reference to it (the address) is important. An address normally consists of user and domain specifications. The standard mailbox naming convention is defined to be "local-part@domain"; contemporary usage permits a much broader set of applications than simple "user names". - RFC 5321 - Simple Mail Transfer Protocol

addressmailboxを資料内で互換性のある表現であることを書きつつ、 mailboxlocal-part@domain という命名規則である旨が書いてある。

そして後半のパートで local-partdomain の文字数の言及がある。

4.5.3.1.1. Local-part The maximum total length of a user name or other local-part is 64 octets. 4.5.3.1.2. Domain The maximum total length of a domain name or number is 255 octets. - RFC 5321 - Simple Mail Transfer Protocol

上記のような記述があるのでオクテット(≒文字数)は…

  • local-part(@より前)は64オクテット
  • domain(@より後)は255オクテット

となります。

ただしdomainの部分はここでは割愛しますが、他の仕様との兼ね合いで実質2文字少なく、253文字が限界となります。

送信仕様である部分の記述

アドレスの仕様は上記の通りだが、送る手順であるSMTP側の手続きの記述として以下のような内容がある。

RCPT TO:<forward-path>

上記の forward-path のアドレスに対してメールを送るという命令のフォーマットであるが、このforward-path に関して以下のような文字数制限の仕様がある。

4.5.3.1.3. Path The maximum total length of a reverse-path or forward-path is 256 octets (including the punctuation and element separators).

このため、実質的にドメインの定義の長さとは関係なく、送信をするSMTPの仕様として256文字が限界ということになる。

ただし、including the punctuation and element separators とあるように区切り文字などの記述を含むため、メールアドレスの区切りを示す <> が必要になるので実質は254文字が限界となる。

参考サイト

余談

仕様上は254文字を確保しておけば盤石だが、セールスフォースでは80文字を限界値として設定しているとのこと

Maximum Size of an address: Per RFCs, an email address can be 256 characters in length. Most email address fields in Salesforce are currently limited to 80 characters. This is generally large enough to cover most email addresses. - Email Address Validation

なので世の中のアドレスは80文字に満たないケースのほうが大多数と思われるので、補足の知見として。