Search code examples
pythonpython-3.xpipemail-validation

How to Check if an Email Exist in Python?


I use Python 3 and I want to check if an email address exists before I send an email.

I've tried pip's validate_email package and it doesn't work at all. It returns true for every string that includes '@' in the middle without symbols. Maybe there's another pip package that does work (I saw packages like validate-email-address, email-validator, py3-validate-email, and email-validator)? Or some code to check that with SMTP?


Solution

  • By default, validate_email doesn't really validate much. You have to enable DNS validation and SMTP validation:

    validate_email(email, check_mx=True, verify=True, smtp_timeout=60)