EZOFISOCR / backend /app /email_validator.py
Seth
update
ced5eff
"""
Email validation utilities to ensure only business emails are allowed.
"""
from fastapi import HTTPException
# List of personal email domains to block
PERSONAL_EMAIL_DOMAINS = {
'gmail.com', 'yahoo.com', 'hotmail.com', 'outlook.com',
'aol.com', 'icloud.com', 'mail.com', 'protonmail.com',
'yandex.com', 'zoho.com', 'gmx.com', 'live.com', 'msn.com',
'me.com', 'mac.com', 'yahoo.co.uk', 'yahoo.co.jp', 'yahoo.fr',
'yahoo.de', 'yahoo.it', 'yahoo.es', 'yahoo.in', 'yahoo.com.au',
'gmail.co.uk', 'gmail.fr', 'gmail.de', 'gmail.it', 'gmail.es',
'gmail.in', 'gmail.com.au', 'hotmail.co.uk', 'hotmail.fr',
'hotmail.de', 'hotmail.it', 'hotmail.es', 'outlook.co.uk',
'outlook.fr', 'outlook.de', 'outlook.it', 'outlook.es',
'rediffmail.com', 'sina.com', 'qq.com', '163.com', '126.com',
'mail.ru', 'inbox.com', 'fastmail.com', 'tutanota.com',
'hey.com', 'pm.me'
}
def is_business_email(email: str) -> bool:
"""
Check if email is a business email (not personal).
Args:
email: Email address to validate
Returns:
True if business email, False if personal email
"""
if not email or '@' not in email:
return False
domain = email.split('@')[1].lower().strip()
return domain not in PERSONAL_EMAIL_DOMAINS
def validate_business_email(email: str) -> None:
"""
Raise exception if email is not a business email.
Args:
email: Email address to validate
Raises:
HTTPException: If email is a personal email domain
"""
if not email:
raise HTTPException(
status_code=400,
detail="Email address is required"
)
if not is_business_email(email):
raise HTTPException(
status_code=400,
detail="Only business email addresses are allowed. Personal email accounts (Gmail, Yahoo, Outlook, etc.) are not permitted. Please use your work email address."
)