Quick Guide to Elements of a Mailto: URL

You can specify default subjects, body text, and more in email links

If you enable your website visitors to send you an email via a mailto: link, you have provided them with a particularly convenient way of establishing contact. All they have to do is click and start typing their message.

But this convenience is not all the mighty mailto: has in store. Let's say you want to define a default Subject, for example, so you know the email was sent via the mailto: link on your website. Or maybe you want to suggest a default text for the body if visitors click on a particular link (you can use this to create a simple survey, for example).

Let's find out how these advanced but by no means difficult uses of mailto: work.

The Mailto: URL

A mailto URL basically consists of three parts. First comes:

  • The word mailto: followed by
  • The recipient's email address, and eventually come
  • Header lines defining default values for various message parts.

To: The Recipient's Email Address

The recipient's email address (that following the mailto: immediately) may actually be more than one address. Multiple addresses are separated by a comma (just as you would use it in the To: line of your email client). Interestingly, a mailto: link is also valid (and works) if it contains no default recipient address at all.

It is therefore perfectly legal to put the default subject (using ?subject=) directly after mailto:. We can create a message with a default subject but no default recipient:


The best things, of course, come last. In the header part of the mailto: URL we can do almost anything. Any header name and value specified in RFC 2822 — The Internet Message Format — can be used in theory.

Not only can we specify Subject: lines, but also Cc: (sending a carbon copy) or Bcc: (a blind carbon copy).

X-Headers Are Note Super Useful

Of particular interest is the ability to invent arbitrary header lines. They only need to be preceded by X- to be legal — maybe you know the ubiquitous X-Mailer: header. Together with an email client capable of filtering based on arbitrary header lines, this makes for wonderful sorting and filtering possibilities.

All header lines are specified in the same way we already know from the subject: [header name]=[header value], for example, X-Z=Y.

Unfortunately, such X-Headers work with hardly any combination of browser and email client, so you cannot rely on them to be sent.

Default Message Text

Finally, there is one special header name: body.

With this header, you can specify text that will appear in the email message body. The body part of the mailto: URL scheme is intended primarily for short textual messages.

Due to the way links work in HTML, special characters must be encoded when you construct a default body for a mailto: link. A space must be translated to %20, for example, and a line break becomes %0D%0A.

Fortunately, you do not have to remember these encodings or do them by hand. Use JavaScript or a convenient mailto: URL encoder instead.

Combining Headers

But how can you have more than one header part, a default Subject, and a default message text, for example? This is done with an ampersand: &.

The first header follows the recipient's address after a question mark: ?. All future headers are attached in any order, separated by ampersands.