Skip to content

Commit f1fdb97

Browse files
Added free & disposable email APIs
1 parent 83817fb commit f1fdb97

File tree

4 files changed

+151
-8
lines changed

4 files changed

+151
-8
lines changed

README.md

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ An api key is required for this module to function.
2323

2424
Go to https://www.mailboxvalidator.com/plans#api to sign up for FREE API plan and you'll be given an API key.
2525

26-
Usage
27-
=====
26+
Usage for validation email
27+
==========================
2828

2929
```javascript
3030
var mbv = require("mailboxvalidator-nodejs");
@@ -181,6 +181,123 @@ The error code if there is any error. See error table below.
181181

182182
The error message if there is any error. See error table below.
183183

184+
185+
Usage for checking if the email is from a disposable email provider
186+
===================================================================
187+
188+
```javascript
189+
var mbv = require("mailboxvalidator-nodejs");
190+
191+
mbv.MailboxValidator_init("YOUR_API_KEY");
192+
193+
mbv.MailboxValidator_disposable_email("[email protected]", mbv_read_disposable);
194+
195+
function mbv_read_disposable(err, res, data) {
196+
if (!err && res.statusCode == 200) {
197+
console.log("email_address: " + data.email_address);
198+
console.log("is_disposable: " + data.is_disposable);
199+
console.log("credits_available: " + data.credits_available);
200+
console.log("error_code: " + data.error_code);
201+
console.log("error_message: " + data.error_message);
202+
}
203+
}
204+
```
205+
206+
Functions
207+
=========
208+
209+
### MailboxValidator_init(api_key)
210+
211+
Creates a new instance of the MailboxValidator object with the API key.
212+
213+
### MailboxValidator_disposable_email(email_address, callback_function)
214+
215+
Performs disposable email check on the supplied email address and a callback function.
216+
217+
Result Fields
218+
=============
219+
220+
### email_address
221+
222+
The input email address.
223+
224+
### is_disposable
225+
226+
Whether the email address is a temporary one from a disposable email provider.
227+
228+
Return values: True, False
229+
230+
### credits_available
231+
232+
The number of credits left to perform validations.
233+
234+
### error_code
235+
236+
The error code if there is any error. See error table below.
237+
238+
### error_message
239+
240+
The error message if there is any error. See error table below.
241+
242+
243+
Usage for checking if the email is from a free email provider
244+
=============================================================
245+
246+
```javascript
247+
var mbv = require("mailboxvalidator-nodejs");
248+
249+
mbv.MailboxValidator_init("YOUR_API_KEY");
250+
251+
mbv.MailboxValidator_free_email("[email protected]", mbv_read_free);
252+
253+
function mbv_read_free(err, res, data) {
254+
if (!err && res.statusCode == 200) {
255+
console.log("email_address: " + data.email_address);
256+
console.log("is_free: " + data.is_free);
257+
console.log("credits_available: " + data.credits_available);
258+
console.log("error_code: " + data.error_code);
259+
console.log("error_message: " + data.error_message);
260+
}
261+
}
262+
```
263+
264+
Functions
265+
=========
266+
267+
### MailboxValidator_init(api_key)
268+
269+
Creates a new instance of the MailboxValidator object with the API key.
270+
271+
### MailboxValidator_free_email(email_address, callback_function)
272+
273+
Performs free email check on the supplied email address and a callback function.
274+
275+
Result Fields
276+
=============
277+
278+
### email_address
279+
280+
The input email address.
281+
282+
### is_free
283+
284+
Whether the email address is from a free email provider like Gmail or Hotmail.
285+
286+
Return values: True, False
287+
288+
### credits_available
289+
290+
The number of credits left to perform validations.
291+
292+
### error_code
293+
294+
The error code if there is any error. See error table below.
295+
296+
### error_message
297+
298+
The error message if there is any error. See error table below.
299+
300+
184301
Errors
185302
======
186303

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
22
"name": "mailboxvalidator-nodejs",
3-
"version": "1.0.0",
3+
"version": "1.1.0",
44
"description": "MailboxValidator API",
55
"keywords": ["mailboxvalidator api", "email validation"],
6-
"homepage": "http://www.mailboxvalidator.com/nodejs",
6+
"homepage": "https://www.mailboxvalidator.com/nodejs",
77
"author": {
88
"name": "MailboxValidator.com",
99
"email": "[email protected]",
10-
"url": "http://www.mailboxvalidator.com/"
10+
"url": "https://www.mailboxvalidator.com/"
1111
},
1212
"files": ["src/mailboxvalidator.js","src/test.js","./README.md"],
1313
"main": "src/mailboxvalidator.js",

src/mailboxvalidator.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
var https = require('https');
22

3-
var version = "1.0";
3+
var version = "1.1";
44
var apikey = "";
55
var singleurl = "https://api.mailboxvalidator.com/v1/validation/single";
6+
var disposableurl = "https://api.mailboxvalidator.com/v1/email/disposable";
7+
var freeurl = "https://api.mailboxvalidator.com/v1/email/free";
68

79
exports.MailboxValidator_init = function MailboxValidator_init(licensekey) {
810
apikey = licensekey;
@@ -17,3 +19,23 @@ exports.MailboxValidator_single_query = function MailboxValidator_single_query(e
1719
callback(e);
1820
});
1921
}
22+
23+
exports.MailboxValidator_disposable_email = function MailboxValidator_disposable_email(email, callback) {
24+
https.get(disposableurl + '?key=' + encodeURIComponent(apikey) + '&email=' + encodeURIComponent(email), function(res) {
25+
res.on('data', function(d) {
26+
callback(null, res, JSON.parse(d));
27+
});
28+
}).on('error', function(e) {
29+
callback(e);
30+
});
31+
}
32+
33+
exports.MailboxValidator_free_email = function MailboxValidator_free_email(email, callback) {
34+
https.get(freeurl + '?key=' + encodeURIComponent(apikey) + '&email=' + encodeURIComponent(email), function(res) {
35+
res.on('data', function(d) {
36+
callback(null, res, JSON.parse(d));
37+
});
38+
}).on('error', function(e) {
39+
callback(e);
40+
});
41+
}

src/test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ var mbv = require("mailboxvalidator-nodejs");
22

33
mbv.MailboxValidator_init("YOUR_API_KEY");
44

5-
mbv.MailboxValidator_single_query("[email protected]", mbv_read_single);
5+
mbv.MailboxValidator_single_query("[email protected]", mbv_results);
66

7-
function mbv_read_single(err, res, data) {
7+
mbv.MailboxValidator_disposable_email("[email protected]", mbv_results);
8+
9+
mbv.MailboxValidator_free_email("[email protected]", mbv_results);
10+
11+
function mbv_results(err, res, data) {
812
if (!err && res.statusCode == 200) {
913
console.log(data);
1014
}

0 commit comments

Comments
 (0)