node package manager
Painless code sharing. npm Orgs help your team discover, share, and reuse code. Create a free org »

webmail-linker

webmail-linker.js

License CI Status Code Coverage

About

This is a JavaScript implementation of Webmail Linker. It can be used as a node.js module or in a browser.

What's Webmail Linker?

Many websites require an email double opt-in during user registration. This project wants to fix the resulting break in user flow when users have to manually switch to their email providers' website to receive the confirmation email.

With Webmail Linker, you can offer a direct link to the user's webmail interface. In addition to the webmail URL, you'll get the name of the email provider and a favicon URL, so you can offer a button like "Check your email on [name and icon of the provider]".

Usage

node.js

Install
npm install webmail-linker
Usage
var webmaillinker = require('webmail-linker'),
provider = webmaillinker.getProviderByEmailAddress('hello@googlemail.com');
 
if(provider) {
    console.log('Check your email at %s (%s)', provider.name, provider.url);
}
Check your email at Gmail (http://gmail.com/)

Browser

Include

We recommend to use the awesome jsDelivr CDN to ship the latest version of webmail-linker.js to the browser:

<script src="//cdn.jsdelivr.net/webmail-linker.js/0.1/webmail-linker.min.js"></script>

You hate CDNs? You can also download webmail-linker.js from GitHub.

Usage
var provider = webmaillinker.getProviderByEmailAddress('hello@googlemail.com');
 
if(provider) {
    console.log('Check your email at %s (%s)', provider.name, provider.url);
}
require(['webmail-linker'], function(webmaillinker) {
    var provider = webmaillinker.getProviderByEmailAddress('hello@googlemail.com');
 
    if(provider) {
        console.log('Check your email at %s (%s)', provider.name, provider.url);
    }
});

API

webmaillinker.getProviders()

console.log(webmaillinker.getProviders());
[
    {
        name: 'Hotmail',
        domains: 'hotmail[.][a-z.]{2,6}',
        url: 'http://hotmail.com/',
        icon: 'https://hotmail.com/favicon.ico'
    },
    {
        name: 'Outlook.com',
        domains: 'live[.][a-z.]{2,6} outlook[.][a-z.]{2,6} msn[.]com windowslive[.]com',
        url: 'http://outlook.com/',
        icon: 'https://hotmail.com/favicon.ico'
    },
    …
]

webmaillinker.getProviderByDomain(domain)

Webmailer found
console.log(webmaillinker.getProviderByDomain('xs4all.nl'));
{
    "name": "XS4ALL Webmail",
    "domains": "xs4all[.]nl",
    "url": "https://webmail.xs4all.nl",
    "icon": "https://webmail.xs4all.nl/images/favicon.ico"
}
Unknown webmailer
console.log(webmaillinker.getProviderByDomain('non.existent'));
null

webmaillinker.getProviderByEmailAddress(domain)

Webmailer found
console.log(webmaillinker.getProviderByDomain('info@edu.uni-graz.at'));
{
    "name": "Uni Graz",
    "domains": "edu[.]uni-graz[.]at",
    "url": "https://sbox.edu.uni-graz.at/",
    "icon": "https://it.uni-graz.at/favicon.ico"
}
Unknown webmailer
console.log(webmaillinker.getProviderByDomain('hello@example.com'));
null
Invalid email address
console.log(webmaillinker.getProviderByDomain('12345'));
Error: Invalid email address "12345" provided.
    at Object.WebmailLinkerGetProviderByEmailAddress [as getProviderByEmailAddress] (./node_modules/webmail-linker/lib/webmail-linker.js:40:10)