Join us
@idjuric660 ă» Sep 12,2024 ă» 8 min read ă» 120 views ă» Originally posted on mailtrap.io
HTML is nearly as old as the internet, and so is one of its most common schemes: mailto. And, even though so many things have changed since then, good olâ mailto is still widely used and taught in HTML courses all around the world.
The way it works is very simple. When placed behind a text and clicked/tapped afterward, it triggers a default email client to be opened and a new email message creator pops up on a screen. Usually, one or more fields are already pre-populated to make life easier for a sender (and make typos, and subsequent email bounces, impossible).
Weâre going to explore different methods of customizing  html mailto links. Weâll also talk about whether itâs still a good approach in the 2020s, and whether there are any viable alternatives. Letâs start!
Mailto is a link so you need to use the <a> tag with its href attribute. A very basic mailto syntax that sends an email after clicking/tapping on âI want free Bitcoinsâ looks like this:
They say the more people you email, the higher the chance of getting what you want, right? If thatâs what you really want, you can let your leads contact a few people at once. Simply insert their addresses separated with commas.
Clicking on such a link will open the default email app or load a web client in the same or a new tab. What exactly happens depends on the default settings of the recipientâs device and browser (more on that later).
If the recipient is logged in to their mail client, an empty new message window will pop up with the pre-filled âTo:â field. Hereâs a Gmail example:
Okay, that was easy to set up. But the email above is still quite empty and it will take some effort from a customer to populate and send it. Chances are, theyâll change their mind in the process and you really want to give away all those bitcoins you were diligently digging. Luckily, pre-filling a âTo:â field is just the start.
To automatically add a text in the subject field, insert it after the âsubjectâ parameter, as in the example below.Â
If this was the first parameter you added to an email address, use â?â to separate them. For any further parameters, youâll use ampersand â&â instead. To separate words, use the â%20â tag.
Chances are you want to pre-populate the email body as well. For that, youâll use the âbodyâ parameter (surprise surprise).
This looks a bit ugly already as, on top of â%20â for separating words, you may also need to separate lines. Use the â%0D%0Aâ tag for this purpose.Â
Now this looks a lot better (depending on who you ask, of course).
If for any noble reason, you just want to keep Kate and John in the loop, you can easily cc and bcc (blind carbon copy) them. For example like this:
Or maybe you donât really want anyone to email you but instead, you want the folks to spread the news about the giveaway youâre doing? You can omit the âToâ field with the following construction:
The last thing that may be useful to know is related to opening a link containing mailto in a new tab.Â
If you use this construction and your clients have a native app set up as a default email client (for example, Microsoft Outlook or Apple Mail), nothing will change. The app will open with a pre-filled email whether you include a âtargetâ parameter or not.
If, however, they have a web-based client such as Gmail as a default email client, it will make a difference. Using target=â_blankâ parameter will cause the email client to open in a new tab, letting a user stay on your website and browse more of your âgreatâ offers. In any other case (also when no target is specified), an email client will load in the same tab.
And what if you wanted to automatically add an attachment? Itâs not that simple and for a reason â automatically fetching files from a userâs hard drive and sending them in an email would lead to some serious abuse. For that reason, thereâs no parameter related to attachments in the mailto protocol.
There can be legitimate use cases for attachments, though.Â
For example, your site is generating a file (say, a simple design) that users may want to send to a friend right away. To enable this, have a server generate a URL to a file and include it in the body of an email for a recipient to download. The same way, if users are to upload a file, generate a link to it when an upload is finished and include it as a hyperlink in emailâs body text.
Either way, itâs going to be a download link, not an attachment thatâs sent. But it should do the job in nearly any situation.
And some good news to wrap up this chapter â there are lots of great tools that will craft a mailto link for you so you donât need to play with the %20 and %0D%0A tags all day long. Some examples include https://mailtolink.me/ and https://htmlstrip.com/mailto-generator
If you need to make sure that all of your mailto links are inserted properly, other links are sent to the right recipients, and that the HTML is not broken in any way, then check out Mailtrap Email Testing.
Email Testing catches your SMTP traffic in a safe environment and letâs you inspect and debug emails in staging, development, and QA stages without spamming recipients. Check the support for a templateâs HTML and CSS with the most popular mailbox providers. Analyze emailsâ Spam Scores and see if your IP appears in any blacklist reports. Then, automate testing flows with Mailtrapâs Email Testing API.
As you can see, setting up a mailto is one of the easiest things in HTML. But no matter how hard you try, many of your visitors still wonât take advantage of it.
Most commonly, their default email client wonât correspond to the actual client they use to send emails. For example, they send with Gmail and Outlook or Apple Mail is set as a default client. (Or the other way around).
If thatâs the case, a client they donât normally use (and are likely not even logged in to) will load when clicking a mailto link. Needless to say, itâs more likely to annoy them rather than help them reach you.
They could technically right-click on a mailto link text and copy the mail address to a clipboard for later use:
But letâs face it, how many will?
Mailto links, and email addresses hidden behind them, are also very easy to harvest. Endless amounts of bots crawl websites day and night and they add to their long lists whatever even resembles an email address. Since a mailto link is directly encoded into a web page, they can collect an email behind it within milliseconds.Â
This can lead to obvious abuse, usually in the form of an endless wave of unwanted messages in your inbox. You could try to obfuscate the address with JavaScript or other methods to hinder the harvest. But, with already excellent spam filters put in place by reputable email clients, it may not be worth the effort. We discuss it in more detail in our article on email obfuscation.
By putting a mailto link out there, you also share your contact details with any legitimate outreach specialists that wish to reach you. Finding all your company emails hidden in the html code is as easy as a single tap on a hunter.io widget (many similar tools are also available).
A contact form is. Itâs easy to reach you this way (as long as you donât add 38 required fields). Your email address is not revealed and, as such, is impossible to harvest. You can gather more specific data this way, forcing users to choose items from a list, as in the example below.
There are also many free and paid resources online for building beautiful contact forms. And, of course, with a bit of design effort you can build your own forms that perfectly complement your website design.
On the downside, a contact form may not be the preferred contact method for some of your clients, used to sending emails back and forth. While bots wonât be able to harvest any email this way, they could still populate the fields of a form and hit the âsendâ button. So if a form is your preferred choice, make sure a latest reCaptcha is in place to quickly filter out these awkward guests.
If mailto links donât open for you the way they should, a quick look at the system or browser settings should do the job.
In Windows, head to Settings -> Apps -> Default apps. Scroll down and pick âChoose default apps by protocolâ from the menu. For âMailtoâ, choose the client of your choice.
On MacOS, open the default Mail app. Log in to your email account (itâs a required step to edit settings). Choose âMailâ from the menu and then âPreferencesâ. Change the default client in the first dropdown list.
If you want Chrome and Gmail to open mailto links for you by default, make sure Google Chrome is picked as the default client on either OS.
In Firefox, you can also specify which client should handle mailto links.Â
Click on the menu button -> Preferences. Then in âGeneralâ go to the âApplicationsâ section and search for âContent Type âmailtoââ. In the action field, pick the desired client:
If Gmail is your client of choice and setting it as default doesnât fix the problem, thereâs one more thing you can do. Launch Chrome and type in chrome://settings/handlers into the address field. You should make sure that mail.google.com is added as a default handler, like in the picture below:
If itâs not, make sure âAllow sitesâŠâ is enabled and open your Gmail account. Youâll see a popup asking whether Gmail can open these html email link. Grant the permission and it should fix the problem.
By now, you should have a pretty good idea of how to customize and use mailto link, and whether you actually want to use it. Explore our blog, where we cover various topics related to emails â important infrastructure choices, software worth using, email configuration for many different frameworks and libraries. And a lot more!
We appreciate you chose this article to know how to link an email in HTML. To discover more interesting topics, read other articles on Mailtrap blog!
Join other developers and claim your FAUN account now!
Technical Content Writer, Mailtrap
@idjuric660Influence
Total Hits
Posts
Only registered users can post comments. Please, login or signup.