Home

Awesome

safe-email

🛡️📧 Protect e-mails against spam and scraping bots

Auto-versioned by bump-everywhere

<!-- [![](https://img.shields.io/npm/dm/safe-email)](https://www.npmjs.com/package/safe-email) [![](https://data.jsdelivr.com/v1/package/npm/safe-email/badge?style=rounded)](https://www.jsdelivr.com/package/npm/safe-email) -->

Easy way to obfuscate e-mails to have spam protection against scraping bots.

How it works 🛡️

Import

Option A: Use CDN

It's the simplest way. Just add it to your page:

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/safe-email@1.1.1/dist/safe-email.min.js"></script>

Option B: Install

<script type="text/javascript" src="/node_modules/safe-email/dist/safe-email.min.js"></script>

top↑

Usage

Encode your e-mail

You'll need to base64 encode to get an obfuscated value for it. Feel free to use your own favorite tool or safe-email generator to base64 encode your e-mail.

Examples

Simplest

  <a title="Email" href="#" data-email_b64="dW5kZXJncm91bmR3aXJlc0BnaXRodWIuY29t"></a>

See it live on CodePen

With all properties

  <a title="Email" href="#" data-email_b64="dW5kZXJncm91bmR3aXJlc0BnaXRodWIuY29t"
    data-body="Hello!" data-subject="About website"></a>

See it live on CodePen

With icon

<a title="Email" href="#" data-email_b64="dW5kZXJncm91bmR3aXJlc0BnaXRodWIuY29t">
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M4 4h16c1.1.1 2 .9 2 2v12c0 1.1-.9 2-2 2H4c-1.1.1-2-.9-2-2V6c0-1.1.9-2 2-2z"></path><polyline points="22,6 12,13 2,6"></polyline></svg>
</a>

See it live on CodePen

As icon is an inner HTML of the parent <a> your e-mail will not be rendered.

Properties

PropertyExplanationRequired / Default
data-email_b64Base64 encoded text of your e-mail. You can encode your e-mail here.Required
data-bodyBody of the e-mailOptional, Defaults to Hi!
data-subjectSubject of the e-mailOptional, Defaults to root domain name + path, e.g. abc.com/path

Any element that has data-email_b64 property defined will have obfuscated mailto: pointing to the given e-mail address. If owner element of this property has no inner HTML, then the e-mail (in obfuscated form) will be rendered.

top↑

Package contents

The deployed packages includes a dist/ folder that adds polyfills to the files and distributes them as:

top↑

GitOps

CI/CD is fully automated for this repo using different Git events & GitHub actions.

safe-email continuous integration and deployment flow

top↑