Skip to content

Commit b61d30e

Browse files
Added disposable and free email APIs
1 parent 2b3644b commit b61d30e

File tree

3 files changed

+143
-4
lines changed

3 files changed

+143
-4
lines changed

MailboxValidator/SingleValidation.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,27 @@ def ValidateEmail(self, email):
1818
return json.loads(res.read())
1919
except:
2020
return None
21+
22+
def DisposableEmail(self, email):
23+
p = { 'key': self.apikey, 'format': 'json', 'email': email }
24+
25+
try:
26+
conn = http.client.HTTPConnection("api.mailboxvalidator.com")
27+
conn.request("GET", "/v1/email/disposable?" + urllib.parse.urlencode(p))
28+
res = conn.getresponse()
29+
# print res.read()
30+
return json.loads(res.read())
31+
except:
32+
return None
33+
34+
def FreeEmail(self, email):
35+
p = { 'key': self.apikey, 'format': 'json', 'email': email }
36+
37+
try:
38+
conn = http.client.HTTPConnection("api.mailboxvalidator.com")
39+
conn.request("GET", "/v1/email/free?" + urllib.parse.urlencode(p))
40+
res = conn.getresponse()
41+
# print res.read()
42+
return json.loads(res.read())
43+
except:
44+
return None

README.md

Lines changed: 117 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ An API key is required for this module to function.
2626
Go to https://www.mailboxvalidator.com/plans#api to sign up for FREE API plan and you'll be given an API key.
2727

2828

29-
Usage
30-
=====
29+
Usage for validating emails
30+
===========================
3131

3232
```python
3333
import MailboxValidator
@@ -183,6 +183,121 @@ The error code if there is any error. See error table below.
183183

184184
The error message if there is any error. See error table below.
185185

186+
187+
Usage for checking if an email is from a disposable email provider
188+
===================================================================
189+
190+
```python
191+
import MailboxValidator
192+
193+
mbv = MailboxValidator.SingleValidation('PASTE_API_KEY_HERE')
194+
results = mbv.DisposableEmail('[email protected]')
195+
196+
if results is None:
197+
print("Error connecting to API.\n")
198+
elif results['error_code'] == '':
199+
print('email_address = ' + results['email_address'] + "\n")
200+
print('is_disposable = ' + results['is_disposable'] + "\n")
201+
print('credits_available = ' + str(results['credits_available']) + "\n")
202+
else:
203+
print('error_code = ' + results['error_code'] + "\n")
204+
print('error_message = ' + results['error_message'] + "\n")
205+
```
206+
207+
Functions
208+
=========
209+
210+
### SingleValidation(api_key)
211+
212+
Creates a new instance of the MailboxValidator object with the API key.
213+
214+
### DisposableEmail(email_address)
215+
216+
Check if the supplied email address is from a disposable email provider.
217+
218+
Result Fields
219+
=============
220+
221+
### email_address
222+
223+
The input email address.
224+
225+
### is_disposable
226+
227+
Whether the email address is a temporary one from a disposable email provider.
228+
229+
Return values: True, False
230+
231+
### credits_available
232+
233+
The number of credits left to perform validations.
234+
235+
### error_code
236+
237+
The error code if there is any error. See error table below.
238+
239+
### error_message
240+
241+
The error message if there is any error. See error table below.
242+
243+
244+
Usage for checking if an email is from a free email provider
245+
============================================================
246+
247+
```python
248+
import MailboxValidator
249+
250+
mbv = MailboxValidator.SingleValidation('PASTE_API_KEY_HERE')
251+
results = mbv.FreeEmail('[email protected]')
252+
253+
if results is None:
254+
print("Error connecting to API.\n")
255+
elif results['error_code'] == '':
256+
print('email_address = ' + results['email_address'] + "\n")
257+
print('is_free = ' + results['is_free'] + "\n")
258+
print('credits_available = ' + str(results['credits_available']) + "\n")
259+
else:
260+
print('error_code = ' + results['error_code'] + "\n")
261+
print('error_message = ' + results['error_message'] + "\n")
262+
```
263+
264+
Functions
265+
=========
266+
267+
### SingleValidation(api_key)
268+
269+
Creates a new instance of the MailboxValidator object with the API key.
270+
271+
### FreeEmail(email_address)
272+
273+
Check if the supplied email address is from a free email provider.
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+
186301
Errors
187302
======
188303

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="MailboxValidator",
8-
version="1.0.13",
8+
version="1.1.0",
99
author="MailboxValidator.com",
1010
author_email="[email protected]",
1111
description="Email verification module for Python using MailboxValidator API. It validates if the email is valid, from a free provider, contains high-risk keywords, whether it\'s a catch-all address and so much more.",
@@ -21,4 +21,4 @@
2121
"License :: OSI Approved :: MIT License",
2222
"Operating System :: OS Independent",
2323
),
24-
)
24+
)

0 commit comments

Comments
 (0)