Skip to content

Commit

Permalink
Update to support for v2 API.
Browse files Browse the repository at this point in the history
  • Loading branch information
MailboxValidator committed Sep 12, 2023
1 parent 740d64a commit 05ed04a
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 62 deletions.
12 changes: 6 additions & 6 deletions MailboxValidator/email_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,35 @@ def __init__(self, apikey):
self.apikey = apikey

def validate_email(self, email):
p = { 'key': self.apikey, 'format': 'json', 'email': email }
p = { 'key': self.apikey, 'format': 'json', 'source': 'sdk-python-mbv', 'email': email }

try:
conn = http.client.HTTPConnection("api.mailboxvalidator.com")
conn.request("GET", "/v1/validation/single?" + urllib.parse.urlencode(p))
conn.request("GET", "/v2/validation/single?" + urllib.parse.urlencode(p))
res = conn.getresponse()
# print res.read()
return json.loads(res.read())
except:
return None

def is_disposable_email(self, email):
p = { 'key': self.apikey, 'format': 'json', 'email': email }
p = { 'key': self.apikey, 'format': 'json', 'source': 'sdk-python-mbv', 'email': email }

try:
conn = http.client.HTTPConnection("api.mailboxvalidator.com")
conn.request("GET", "/v1/email/disposable?" + urllib.parse.urlencode(p))
conn.request("GET", "/v2/email/disposable?" + urllib.parse.urlencode(p))
res = conn.getresponse()
# print res.read()
return json.loads(res.read())
except:
return None

def is_free_email(self, email):
p = { 'key': self.apikey, 'format': 'json', 'email': email }
p = { 'key': self.apikey, 'format': 'json', 'source': 'sdk-python-mbv', 'email': email }

try:
conn = http.client.HTTPConnection("api.mailboxvalidator.com")
conn.request("GET", "/v1/email/free?" + urllib.parse.urlencode(p))
conn.request("GET", "/v2/email/free?" + urllib.parse.urlencode(p))
res = conn.getresponse()
# print res.read()
return json.loads(res.read())
Expand Down
110 changes: 55 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,73 +99,73 @@ Sample Codes

```python
import MailboxValidator
mbv = MailboxValidator.EmailValidation('PASTE_API_KEY_HERE')
results = mbv.validate_email('example@example.com')
if results is None:
print("Error connecting to API.\n")
elif results['error_code'] == '':
print('email_address = ' + results['email_address'] + "\n")
print('domain = ' + results['domain'] + "\n")
print('is_free = ' + results['is_free'] + "\n")
print('is_syntax = ' + results['is_syntax'] + "\n")
print('is_domain = ' + results['is_domain'] + "\n")
print('is_smtp = ' + results['is_smtp'] + "\n")
print('is_verified = ' + results['is_verified'] + "\n")
print('is_server_down = ' + results['is_server_down'] + "\n")
print('is_greylisted = ' + results['is_greylisted'] + "\n")
print('is_disposable = ' + results['is_disposable'] + "\n")
print('is_suppressed = ' + results['is_suppressed'] + "\n")
print('is_role = ' + results['is_role'] + "\n")
print('is_high_risk = ' + results['is_high_risk'] + "\n")
print('is_catchall = ' + results['is_catchall'] + "\n")
print('mailboxvalidator_score = ' + str(results['mailboxvalidator_score']) + "\n")
print('time_taken = ' + str(results['time_taken']) + "\n")
print('status = ' + results['status'] + "\n")
print('credits_available = ' + str(results['credits_available']) + "\n")
else:
print('error_code = ' + results['error_code'] + "\n")
print('error_message = ' + results['error_message'] + "\n")

mbv = MailboxValidator.EmailValidation('PASTE_API_KEY_HERE')
results = mbv.validate_email('example@example.com')

if results is None:
print("Error connecting to API.\n")
elif 'error' not in results:
print('email_address = ' + results['email_address'] + "\n")
print('domain = ' + results['domain'] + "\n")
print('is_free = ' + str(results['is_free']) + "\n")
print('is_syntax = ' + str(results['is_syntax']) + "\n")
print('is_domain = ' + str(results['is_domain']) + "\n")
print('is_smtp = ' + str(results['is_smtp']) + "\n")
print('is_verified = ' + str(results['is_verified']) + "\n")
print('is_server_down = ' + str(results['is_server_down']) + "\n")
print('is_greylisted = ' + str(results['is_greylisted']) + "\n")
print('is_disposable = ' + str(results['is_disposable']) + "\n")
print('is_suppressed = ' + str(results['is_suppressed']) + "\n")
print('is_role = ' + str(results['is_role']) + "\n")
print('is_high_risk = ' + str(results['is_high_risk']) + "\n")
print('is_catchall = ' + str(results['is_catchall']) + "\n")
print('mailboxvalidator_score = ' + str(results['mailboxvalidator_score']) + "\n")
print('time_taken = ' + str(results['time_taken']) + "\n")
print('status = ' + str(results['status']) + "\n")
print('credits_available = ' + str(results['credits_available']) + "\n")
else:
print('error_code = ' + str(results['error']['error_code']) + "\n")
print('error_message = ' + results['error']['error_message'] + "\n")
```


## Check if an email is from a disposable email provider

```python
import MailboxValidator
mbv = MailboxValidator.EmailValidation('PASTE_API_KEY_HERE')
results = mbv.is_disposable_email('example@example.com')
if results is None:
print("Error connecting to API.\n")
elif results['error_code'] == '':
print('email_address = ' + results['email_address'] + "\n")
print('is_disposable = ' + results['is_disposable'] + "\n")
print('credits_available = ' + str(results['credits_available']) + "\n")
else:
print('error_code = ' + results['error_code'] + "\n")
print('error_message = ' + results['error_message'] + "\n")

mbv = MailboxValidator.EmailValidation('PASTE_API_KEY_HERE')
results = mbv.is_disposable_email('example@example.com')

if results is None:
print("Error connecting to API.\n")
elif 'error' not in results:
print('email_address = ' + results['email_address'] + "\n")
print('is_disposable = ' + str(results['is_disposable']) + "\n")
print('credits_available = ' + str(results['credits_available']) + "\n")
else:
print('error_code = ' + results['error']['error_code'] + "\n")
print('error_message = ' + results['error']['error_message'] + "\n")
```

## Check if an email is from a free email provider

```python
import MailboxValidator
mbv = MailboxValidator.EmailValidation('PASTE_API_KEY_HERE')
results = mbv.is_free_email('example@example.com')
if results is None:
print("Error connecting to API.\n")
elif results['error_code'] == '':
print('email_address = ' + results['email_address'] + "\n")
print('is_free = ' + results['is_free'] + "\n")
print('credits_available = ' + str(results['credits_available']) + "\n")
else:
print('error_code = ' + results['error_code'] + "\n")
print('error_message = ' + results['error_message'] + "\n")

mbv = MailboxValidator.EmailValidation('PASTE_API_KEY_HERE')
results = mbv.is_free_email('example@example.com')

if results is None:
print("Error connecting to API.\n")
elif 'error' not in results:
print('email_address = ' + results['email_address'] + "\n")
print('is_free = ' + str(results['is_free']) + "\n")
print('credits_available = ' + str(results['credits_available']) + "\n")
else:
print('error_code = ' + results['error']['error_code'] + "\n")
print('error_message = ' + results['error']['error_message'] + "\n")
```

Errors
Expand All @@ -183,4 +183,4 @@ Errors
Copyright
=========

Copyright (C) 2018-2021 by MailboxValidator.com, support@mailboxvalidator.com
Copyright (C) 2018-2023 by MailboxValidator.com, support@mailboxvalidator.com
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="MailboxValidator",
version="1.2.0",
version="1.3.0",
author="MailboxValidator.com",
author_email="support@mailboxvalidator.com",
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.",
Expand Down

0 comments on commit 05ed04a

Please sign in to comment.