python smtplib 模块的 smtp_ssl 连接方法不起作用
python smtplib module's smtp_ssl connect method is not working
电子邮件地址不是我在这里提到的那个。
这是代码:
import dns.resolver
import smtplib
email_address = "BC@xyz.com"
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)
我在 server.connect() 上遇到的错误是:
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
records = dns.resolver.resolve(domain_name, 'MX')
...
server.connect(mxRecord,465)
端口 465 和 587 用于联系该提供商的客户的邮件服务器。访问这些端口通常也需要身份验证。
由 MX 记录公布的邮件服务器期望在标准 SMTP 端口 25 上建立连接。这些连接必须以普通方式而非 SSL 方式完成。要升级到 SSL,必须在普通连接上发出 STARTTLS command。
电子邮件地址不是我在这里提到的那个。
这是代码:
import dns.resolver
import smtplib
email_address = "BC@xyz.com"
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)
我在 server.connect() 上遇到的错误是:
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
records = dns.resolver.resolve(domain_name, 'MX') ... server.connect(mxRecord,465)
端口 465 和 587 用于联系该提供商的客户的邮件服务器。访问这些端口通常也需要身份验证。
由 MX 记录公布的邮件服务器期望在标准 SMTP 端口 25 上建立连接。这些连接必须以普通方式而非 SSL 方式完成。要升级到 SSL,必须在普通连接上发出 STARTTLS command。