Markdown is a lightweight markup language that is used to add formatting elements to plain text. This article will focus on one of Markdown’s powerful features?creating email links using “mailto”. We will show you how to create functional email links in Markdown that can auto-populate the recipient, subject, and body of an email.

In its purest form, the “mailto” syntax is as follows:

[Link Text](mailto:[email protected])

This will look like: Link Text

And the output of running this code will be a clickable text “Link text”, that prompts your email client to send an email to the defined email address when you click on it.

Adding More Details

However, it’s often useful to pre-populate the email with a subject, recipient, and body copy. You can achieve this with the following syntax:

[Link Text](mailto:[email protected]?subject=Your%20Subject&body=Body%20text)

This generates a link that, when clicked, opens a user’s default mail client with pre-populated email fields. The “subject” field in the URL strings is followed by an equals sign and the desired subject text. The same goes for the “body” field.

Spaces are encoded as %20, and line breaks can be inserted with %0A.

Escaping Special Characters

Ensure that you properly escape special characters to prevent any issues. For example, use %20 for a space, and %40 for @.

[Email Me](mailto:email%40domain.com?subject=Hello%20World)

Closing Remarks

The flexibility of Markdown offers countless possibilities for formatting and structuring content. Using “mailto” links in Markdown can be a smooth sail, as illustrated in this guide. When you need to point people to get into their email and start writing to a specific address, use this trick.

For more on Markdown, have a look at our guide on how to bold text in Markdown or rendering Markdown in React.

Additional References

[1] Daring Fireball: Markdown Syntax
[2] Markdown Guide


Happy coding!

Disclaimer: Please make sure any email addresses you share in your Markdown files are supposed to be public. It is a common practice to avoid plain email addresses in public repos to evade email harvesting bots. Always prioritize your privacy, as well as that of others.