|
from email_validator import EmailNotValidError |
|
from email_validator import validate_email as validate_email_address |
|
|
|
|
|
def validate_email(email: str) -> str: |
|
if not email: |
|
return "" |
|
|
|
try: |
|
validation = validate_email_address(email, check_deliverability=False) |
|
|
|
|
|
|
|
|
|
email = validation.email |
|
except EmailNotValidError as e: |
|
|
|
email = "" |
|
print(str(e)) |
|
|
|
return email |
|
|
|
|
|
def validate_multiple_emails(emails: str) -> str: |
|
if not emails: |
|
return "" |
|
|
|
for email in emails.split(sep=","): |
|
email = validate_email(email=email.strip(" ")) |
|
if not email: |
|
emails = "" |
|
break |
|
|
|
return emails |
|
|