Home > Blockchain >  SMTP_HELO returns timeout when running email address validation
SMTP_HELO returns timeout when running email address validation

Time:06-12

Using library py3-validate-email-1.0.5 (more here) to check if email address is valid, including SMTP check, I wasn't able to make it through check_smtp step, because I get following error:

Python script

from validate_email import validate_email
from validate_email import validate_email_or_fail
from csv import DictReader

# iterate over each line by column name
with open('email-list.csv', 'r') as read_obj:
    csv_dict_reader = DictReader(read_obj, delimiter=';')
    for row in csv_dict_reader:
        i = 1
        while i < 21:
            header_name = 'Email' str(i)
            if validate_email_or_fail(
                email_address=row[header_name],
                check_format=True,
                check_blacklist=True,
                check_dns=True,
                dns_timeout=10,
                check_smtp=True,
                smtp_timeout=5,
                smtp_helo_host='emailsrv.domain.com',
                smtp_from_address='[email protected]',
                smtp_skip_tls=False,
                smtp_tls_context=None,
                smtp_debug=False):
                print('Email '   row[header_name]   ' is valid.')
            else:
                print('Email '   row[header_name]   ' is invalid.')
            i  = 1

Error:

Traceback (most recent call last):
  File "//./main.py", line 13, in <module>
    if validate_email_or_fail(
  File "/usr/local/lib/python3.9/site-packages/validate_email/validate_email.py", line 59, in validate_email_or_fail
    return smtp_check(
  File "/usr/local/lib/python3.9/site-packages/validate_email/smtp_check.py", line 229, in smtp_check
    return smtp_checker.check(hosts=mx_records)
  File "/usr/local/lib/python3.9/site-packages/validate_email/smtp_check.py", line 197, in check
    raise SMTPTemporaryError(error_messages=self.__temporary_errors)
validate_email.exceptions.SMTPTemporaryError: Temporary error in email address verification:
mx.server.com: 451 timed out (in reply to 'connect')

I figured there is problem with my DNS settings (probably), so I dockerized the script and run it on AWS EC2, where I have used elastic IP, attached it to the EC2 instance where docker container is running, I also setup reverse DNS for domain emailsrv.domain.com with this elastic IP. Tried to run the script, no change.

Then I added MX record pointing to the emailsrv.domain.com, but still no change. The DNS records are setup properly, because I have checked it with multiple DNS tools available.

Since the library doesn't require to actually use my email address login details, I wonder what can be the problem? Just to be sure, the email address used in the script doesn't exist, since I don't have smtp server setup on that instance, obviously.

Any ideas?

CodePudding user response:

Reason behind this was closed port on AWS EC2 instance. Opening the port in security group is not enough, you must send a request to AWS so they remove the restriction on port 25.

When they did that, works flawlessly.

  • Related