diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..b7d589a --- /dev/null +++ b/app/main.py @@ -0,0 +1,60 @@ +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.0", + 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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..703aa27 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,24 @@ +filelock==3.18.0 +idna==3.10 +py3-validate-email==1.0.5.post2 +dnspython==2.7.0 + +annotated-types==0.7.0 # FastAPI +anyio==4.9.0 # FastAPI +fastapi==0.115.12 # FastAPI +idna==3.10 # FastAPI +pydantic==2.11.4 # FastAPI +pydantic-core==2.33.2 # FastAPI +sniffio==1.3.1 # FastAPI +starlette==0.46.2 # FastAPI +typing-extensions==4.13.2 # FastAPI +typing-inspection==0.4.0 # FastAPI + +click==8.1.7 # uvicorn server +httptools==0.6.4 # uvicorn server +pyyaml==6.0.2 # uvicorn server +uvicorn==0.32.0 # uvicorn server +uvloop==0.21.0 # uvicorn server +watchfiles==0.24.0 # uvicorn server +websockets==14.1 # uvicorn server +gunicorn==23.0.0 # uvicorn server diff --git a/validate_mail.py b/validate_mail.py new file mode 100644 index 0000000..eba7f1c --- /dev/null +++ b/validate_mail.py @@ -0,0 +1,20 @@ +from validate_email import validate_email + +# Replace with your target email +emails =[ + "conrad@noah.tech", + "bernd@noah.tech" +] +for mail in emails: + is_valid = validate_email( + email_address=mail, + check_format=True, + check_blacklist=True, + check_dns=True, + dns_timeout=10, + check_smtp=True, + smtp_timeout=10, + + ) + + print(f"Is '{mail}' valid? -> {is_valid}")