问题
I am trying to write a python script which would check the authenticity of a mail ID from a csv file which has the whole list. I am doing these three check for every email ID
1. Regex check
regex = re.compile(
r'^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})$')
2. Domain Check
splitAddress = email.split('@')
domain = str(splitAddress[1])
records = dns.resolver.query(domain, 'MX')
mxRecord = records[0].exchange
mxRecord = str(mxRecord)
3. SMTP conversation check
server = smtplib.SMTP()
server.set_debuglevel(0)
server.connect(mxRecord)
server.helo(server.local_hostname)
server.mail('abc@bt.com')
code, message = server.rcpt(str(email))
server.quit()
The issues I am having with this is that it doesn't run on some of the domains like Yahoo,Outlook and some random domain from my lists is pmrelocations.com
The traceback error that I am getting is:
Traceback (most recent call last):
File "mxrecord.py", line 41, in <module>
server.helo(server.local_hostname)
File "C:\Python27\lib\smtplib.py", line 404, in helo
(code, msg) = self.getreply()
File "C:\Python27\lib\smtplib.py", line 369, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
You can check the complete code here: https://github.com/Rwarlock/mxrecordchecker/blob/master/mxrecord.py
I understand that this code needs optimizations but I am currently focusing on making it work and will optimize it once its completely coded with all real life checks being performed.
I am not getting any leads on how to resolve the issue. I am very beginner with all the SMTP and DNS things. Please guide as to how can I solve this problem.
来源:https://stackoverflow.com/questions/54670906/unable-to-check-mx-records-for-domains-such-as-yahoo-and-outlooks-etc