'How to verify an email in python without sending an email by verifying records?

import smtplib, ssl
import dns.resolver,socket

smtp_server= 'smtp.gmail.com'
port = 465
sender = '[email protected]'
pssword = ''
addressToVerify = '[email protected]'

context = ssl.create_default_context()

domain_name = addressToVerify.split('@')[1]
print('domain_name :  '+domain_name)
records = dns.resolver.resolve(domain_name, 'MX')
mxRecord = records[0].exchange
print(mxRecord)

host = socket.gethostname()
print('hosttttttttttt==',host)

try:
    server = smtplib.SMTP_SSL(smtp_server,port)
    server.ehlo()
    #server.starttls(context = context)
    server.ehlo()
    server.login(sender,pssword)
    ss = server.connect(str(mxRecord),465)
    #print(ss)
    pp = server.verify(addressToVerify)
    print(pp)
    ss = server.rcpt(addressToVerify)
    print(ss)
    print('ok')

except Exception as e:
    print(e)

I was trying to verify the email address but it was throwing an error while it was not connecting mxrecords

[WinError 10060] A connection attempt failed because the connected party did not properly respond 
after a period of time, or established connection failed because connected host has failed to respond

It is not connecting to the MX records. while verifying at

RCPT (503, b'5.5.1 MAIL first. p2-20020a17090ad30200b001cd4989feb7sm14376983pju.3 - gsmtp')

This 503 error code representing that `The server has encountered a bad sequence of commands, or it requires an authentication.

Suggest a standard way of verifying an email, please.



Solution 1:[1]

Suggest a standard way of verifying an email, please.

You can not, without sending an email with a nonce, and waiting for it to be used in some timeframe.

Servers won't let you arbitrarily test the existence of email addresses, otherwise this would be an heaven for spammers.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Patrick Mevzek