Mailgun plugin

Validate an email address by using Mailgun API

Usage

Mailgun is one of most popular email services. It also provides free API to validate an email address based on:

  • Mailbox detection
  • Syntax checks (RFC defined grammar)
  • DNS validation
  • Spell checks
  • Email Service Provider (ESP) specific local-part grammar (if available)

To use it, you need to sign up for a Mailgun account and get a free API key.

The following piece of code is the starting point to use the Mailgun plugin:




    


    
...
document.addEventListener('DOMContentLoaded', function(e) { FormValidation.formValidation( document.getElementById('demoForm'), { fields: { ... }, plugins: { ..., mailgun: new FormValidation.plugins.Mailgun({ apiKey: ..., field: ..., message: ..., suggestion: ..., }), }, } ); });

The sample code above assumes that the FormValidation files are placed inside the vendors directory. You might need to change the path depending on where you place them on the server.

Options

Option Type Description
apiKey * String The API key provided by Mailgun
field * String The field name that will be validated
message * String Error message indicates the input is not valid
suggestion Boolean Show suggestion if the email is not valid. By default, it is set to false

Basic example

You can use the following sample email addresses to test with your app.

Description Sample
Does not meet Gmail minimum local-part length of 6 characters john@gmail.com
Invalid, because gmaill.com does not have valid MX records john.smith@gmaill.com
Invalid because while microsoft.io does not have any MX records, it does have fallback A records, but alas no Mail Exchanger responds john@microsoft.io
Meets Gmail 6 character minimum and all other requirements john.smith@gmail.com
Meets pure syntax checks "hello world"@domain.com
Suggest new email address hello@gail.com

The following sample code demonstrates how to use Mailgun plugin to validate email address which its form is made with Tachyons:




    
    
    


    
Email address
document.addEventListener('DOMContentLoaded', function(e) { FormValidation.formValidation( document.getElementById('demoForm'), { fields: { email: { validators: { notEmpty: { message: 'The email address is required' }, emailAddress: { message: 'The input is not a valid email address' }, } }, }, plugins: { trigger: new FormValidation.plugins.Trigger(), tachyons: new FormValidation.plugins.Tachyons(), submitButton: new FormValidation.plugins.SubmitButton(), icon: new FormValidation.plugins.Icon({ valid: 'fa fa-check', invalid: 'fa fa-times', validating: 'fa fa-refresh', }), mailgun: new FormValidation.plugins.Mailgun({ // Put your Mailgun public API key here apiKey: '...', field: 'email', message: 'The email address is not valid', suggestion: true, }), }, } ); });