email address is not the one that I mentioned here.
This is the code:
import dns.resolver
import smtplib
email_address = "[email protected]"
domain_name = email_address.split('@')[1]
records = dns.resolver.resolve(domain_name, 'MX')
mxRecord = records[0].exchange
mxRecord = str(mxRecord)
print(mxRecord)
server = smtplib.SMTP_SSL()
server.set_debuglevel(1)
server.connect(mxRecord,465)
The error that I am getting on server.connect() is:
self.sock = self._get_socket(host, port, self.timeout)
new_socket = super()._get_socket(host, port, timeout)
return socket.create_connection((host, port), timeout,
TimeoutError: [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
CodePudding user response:
records = dns.resolver.resolve(domain_name, 'MX') ... server.connect(mxRecord,465)
Port 465 and 587 are used for contacting the mail server of a provider for the customers of this provider. Accessing these ports also usually requires authentication.
A mail server announced by an MX record expects instead connections on the standard SMTP port 25. These connections must be done in plain, not SSL. To upgrade to SSL the STARTTLS command must be issued on the plain connection.