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 web site. 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.
The recipient's email address (that following the mailto: immediately) may actually be more than one address. Multiple addresses are separated by 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: mailto:?subject=Doc,%20do%20da%20dance.
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).
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's 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".
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.
For example (the line breaks are here only to ensure neat looks; of course you would not insert them into the URL):