我使用的是 Python3.7,运行代码时出现以下错误:
TimeoutError: [WinError 10060] 连接尝试失败,因为连接方在一段时间后没有正确响应,或者由于连接的主机未能响应而建立的连接失败
这是我的代码:
import smtplib
from email import encoders
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
server = smtplib.SMTP('smtp.gmail.com', 25)
server.connect("smtp.gmail.com",465)
server.ehlo()
with open('password.txt', 'r') as f:
password = f.read()
server.login('mymail@gmail.com', password)
msg = MIMEMultipart()
msg['From'] = 'mymail@gmail.com'
msg['To'] = 'mymail2@yahoo.com'
msg['Subject'] = 'Mail testing with Python'
with open('message.txt', 'r') as f:
message = f.read()
msg.attach(MIMEText(message, 'plain'))
text = msg.as_string()
server.sendmail('mymail@gmail.com', 'mymail2@yahoo.com', text)
问题是什么?我的代码有错误还是只是我的网络连接有错误?
aluckdog
相关分类