How to format an email 'From' header that contains a comma

岁酱吖の 提交于 2019-12-03 11:03:56

问题


The standard way to format the 'From' email header is

From: John Doe <john.doe@example.com>

But what to do if there's a comma in the name?

From: John Doe, chief bottle washer <john.doe@example.com>

If I do that, my MTA automatically converts this into:

From: John@this.server.com, Doe@this.server.com, chief bottle washer <john.doe@example.com>

My first guess is to use double-quotes around the full name, but I can't find any official documentation confirming this and I'd like my emails to be readable by all email clients.


回答1:


To elaborate on the answer by @Fls'Zen, yes the proper method is to enclose the name in double-quotes.

From a practical point of view there's no harm in wrapping all names in double-quotes, just be sure to escape a double-quote if it appears in the display name \" (or just replace with a single-quote). But if you want to be completely by the spec, you shouldn't use the double quotes if you don't have to.

For all the dense details, E-mail header fields are defined by RFC 5322. The relevant section for multiple originators in the From header is 3.6.2, and the relevant sections for quoting delimiters is 3.2.1 and 3.2.4.




回答2:


E-mail header fields are defined by RFC 5322. The relevant section for multiple originators in the From header is 3.6.2. The relevant sections for quoting delimiters is 3.2.1 and 3.2.4.




回答3:


When the following regular expression matches, then an email display address must be quoted.

[^-A-Za-z0-9!#$%&'*+/=?^_`{|}~\s]

For ASCII characters, this can be done by escaping any double quote characters with a backslash, and enclosing the string in double quotes. For non-ASCII characters, the more complex MIME escaping is required.



来源:https://stackoverflow.com/questions/15555563/how-to-format-an-email-from-header-that-contains-a-comma

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!