David Walsh Blog

Enhanced Email Validation with mailboxlayer

Validation is an important part of managing any data you receive, especially when it comes to web forms.  If you really want to be secure with the data, you use HTML5 validation rules, JavaScript validation, and then the most importantly layer, the server-side layer.  Even then, you’re only validating text patterns.

What’s one of the most valuable data formats?  Email addresses.  So much of advertising these days is done by email and email services require a level of quality in email lists.  That means you need to perform every type of validation possible.  mailboxlayer allows you to easy validation various aspects of an email address in one simple call.  Let’s check it out!

Quick Hits

Using mailboxlayer

As with apilayer’s other services, mailboxlayer is easy to use.  Make a single call providing an access code and an email address to get important information about the email address:


curl https://apilayer.net/api/check?access_key=MY_KEY
    &email=SOME_USER@davidwalsh.name
    &smtp=1
    &format=1

This call presents a wealth of information:


{
  "email":"SOME_USER@davidwalsh.name",
  "did_you_mean":"",
  "user":"SOME_USER",
  "domain":"davidwalsh.name",
  "format_valid":true,
  "mx_found":true,
  "smtp_check":true,
  "catch_all":null,
  "role":false,
  "disposable":false,
  "free":false,
  "score":0.96
}

Let’s look at a few important pieces of information in the response:

The information provided back from mailboxlayer is invaluable.

Privacy

If you’re hesitant to use a third party service to check email addresses due to privacy or other concerns, simply swap out the username of the email address:


// email = REAL_USER@davidwalsh.name
var addressSplit = email.split('@');
addressSplit[0] = 'MASKED_USER';
var maskedAddress = addressSplit.join('');

// Now make the request

By swapping out the handle, you aren’t directly exposing the true email address but still get information about the domain.

Just like currencylayer and eversign, mailboxlayer is so easy to use.  No complicated API calls or parameters — just one simple call to get all the information you need.  These guys are really hitting the mark with API design and usability!