39

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.

Dalin
  • 3,012
  • 1
  • 21
  • 21
  • 5
    This question and the answers have a surprising number of negative votes. The information seems good. Why the downvotes? – Dave Cameron Feb 15 '14 at 05:31

3 Answers3

35

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.

Community
  • 1
  • 1
Dalin
  • 3,012
  • 1
  • 21
  • 21
5

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.

Community
  • 1
  • 1
Diomidis Spinellis
  • 18,734
  • 5
  • 61
  • 83
  • 1
    Whitespace characters are allowed. So this would be `[^-A-Za-z0-9!#$%&\'*+-/=?^_\`{|}~\\s]+` with `\s` being the white space character class. – JonnyJD Sep 20 '17 at 09:47
  • 1
    And the second `-` is too much. Like this it includes all characters between `+` and `/`. So the complete regex working for me is: `[^-A-Za-z0-9!#$%&\'*+/=?^_\`{|}~\\s]+` The `'` only needs to be escaped when you enclose the string with it. So enclosing in `"` this would be correct: `[^-A-Za-z0-9!#$%&'*+/=?^_\`{|}~\\s]+` – JonnyJD Sep 20 '17 at 12:07
  • Thank you, I incorporated your suggestions. – Diomidis Spinellis Sep 21 '17 at 12:22
3

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.

Community
  • 1
  • 1
Fls'Zen
  • 4,594
  • 1
  • 29
  • 37
  • If I'm interpreting this RFC correctly (and these things are by no means human readable), then the solution is to enclose in double quotes From: "John Doe, chief bottle washer" ??? – Dalin Mar 22 '13 at 15:38
  • Furthermore, is there any harm in wrapping all names in double quotes, regardless of whether a comma (or other illegal character) is present? – Dalin Mar 22 '13 at 15:49
  • 2
    Yes, that's the correct way. Using double quotes all the time doesn't hurt anything, just make sure to escape a double-quote if it appears in the display name. – Fls'Zen Mar 23 '13 at 02:57