TIP: Never leave your email address raw in the mailto link! Here's what to do instead
Tags: beginners, webdev, html, security
Published: 2021-04-14 17:36:09

---
canonical_url: https://thalita.dev/writings/encoded-email/
---

Usually, when you leave your email address on your website for people to click on, you may do something like this:

```HTML
<a href="mailto:name@example.com">name@example.com</a>
```

Right?

This is, however, the perfect recipe to get spam into your email!

# This is how email harvesting works

In order for spambots to get a nice long list of emails to annoy people to click their suspicious-looking links, they use email harvesters to curate these lists. Emails are typically found on websites where people leave theirs to be contacted.

Some people think this is easy to solve simply by masking the email like `name[AT]example[DOT]com`. This, however, doesn't solve anything due to two things:

1. The mailto link still contains the actual email address as you can't replace it with the one above. Since email harvesters look into the source code of your website, they'd still be able to get your email.
2. Most email harvesters are advanced enough to detect common patterns like [AT] and (AT) and such, so they won't do much.

So, what now?

# Encode your email address

Fortunately, there's a way to make your email address unreadable for email harvesters!

You may have seen characters like `&amp;` and `&gt;` in HTML before. These are called **HTML entities**. These are symbols that have been encoded so they won't be mistaken for HTML tags.

However, what not many people know is that you can encode every single character into an HTML entity. And even better, putting these into your hrefs will convert them back into regular text for normal visitors that are visiting your website rather than looking at the source code. It's perfect for this situation!

HTML entities for regular letters are made of HEX encoding. The HTML entities would look like like `&#HEXCODE;`

# Let's do it!

Use [this handy tool](https://onlineutf8tools.com/convert-utf8-to-html-entities) to convert! Make sure to copy the entire href link, not just your email address!

![Example screenshot of how to convert the link](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4wp8z4lq06l79pradccx.jpg) 

After that, copy-paste that string into your href and you're done! Here's how it should look like:

```HTML
<a href="&#x6d;&#x61;&#x69;&#x6c;&#x74;&#x6f;&colon;&#x6e;&#x61;&#x6d;&#x65;&commat;&#x65;&#x78;&#x61;&#x6d;&#x70;&#x6c;&#x65;&period;&#x63;&#x6f;&#x6d;">My email</a>
```

This makes the whole thing a lot harder to decypher for most email harvesters. That, while still keeping the link clickable for others! On top of that, using inspect element to check the HTML gives you the decoded email, even though the source code has it encoded!

![Comparison of devtools and source code](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vb34uh9ajgg3gohr8aa7.jpg) 

This means that it still ends up being readable for humans.

It's even better if you use some non-traditional way of masking your email address in the actual text, or just don't use your email at all (like in the sample above).

We're all good now! No more disappointments that you think you just got a client but it turns out to be spam!

![Good job fellow dev](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/85t5l2vp28xdw748e2tv.gif)

---

![Thalita logo](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sa0hfs0886uf0g7c0b7e.png)

[Twitter](https://twitter.com/thalitadev) | [Website](https://thalita.dev)