mirror of
https://github.com/creyD/email_valid.git
synced 2026-04-12 19:30:30 +02:00
60 lines
1.5 KiB
Python
60 lines
1.5 KiB
Python
from fastapi import FastAPI
|
|
from validate_email import validate_email
|
|
|
|
# App Setup
|
|
app = FastAPI(
|
|
title="MailConfirm API",
|
|
description="API for telegram bot for confirming emails.",
|
|
version="0.1.4",
|
|
docs_url="/",
|
|
redoc_url=None,
|
|
debug=False,
|
|
swagger_ui_parameters={
|
|
"docExpansion": "list",
|
|
"displayOperationId": True,
|
|
"defaultModelsExpandDepth": 5,
|
|
"defaultModelExpandDepth": 5,
|
|
"filter": True,
|
|
"displayRequestDuration": True,
|
|
"defaultModelRendering": "model",
|
|
"persistAuthorization": True,
|
|
},
|
|
)
|
|
|
|
|
|
@app.post("/validate_email", operation_id="validate_email")
|
|
def validate_mail(email: str) -> bool:
|
|
"""
|
|
Validate email address using regex.
|
|
"""
|
|
is_valid = validate_email(
|
|
email_address=email,
|
|
check_format=True,
|
|
check_blacklist=True,
|
|
check_dns=True,
|
|
dns_timeout=10,
|
|
check_smtp=True,
|
|
smtp_timeout=10,
|
|
)
|
|
return is_valid or False
|
|
|
|
|
|
@app.post("/validate_multiple_emails", operation_id="validate_multiple_emails")
|
|
def validate_multiple_emails(emails: list[str]) -> dict[str, bool]:
|
|
"""
|
|
Validate multiple email addresses using regex.
|
|
"""
|
|
results = {}
|
|
for email in emails:
|
|
is_valid = validate_email(
|
|
email_address=email,
|
|
check_format=True,
|
|
check_blacklist=True,
|
|
check_dns=True,
|
|
dns_timeout=10,
|
|
check_smtp=True,
|
|
smtp_timeout=10,
|
|
)
|
|
results[email] = is_valid or False
|
|
return results
|