Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
664 views
in Technique[技术] by (71.8m points)

python3 发送邮件到126邮箱失败,提示 TimeoutError: [WinError 10060]

我用下面代码试图发送邮件到126邮箱失败,请问是什么原因

import smtplib
from email import encoders 
from email.header import Header 
from email.mime.text import MIMEText 
from email.utils import parseaddr 
from email.utils import formataddr 

def format_addr(s):
    name, addr = parseaddr(s)
    return formataddr((Header(name, "utf-8").encode(), addr))

from_email = "[email protected]"
from_email_pwd = "xxxxxxx"
to_email = "[email protected]"
smtp_server = "smtp.126.com"

msg = MIMEText("<html><body><h3>hello</h3><p>hello, send by python</p></body></html>", "html", "utf-8")
msg["From"] = format_addr("%s" %(from_email))
msg["To"] = format_addr("%s" %(to_email))
msg["Subject"] = Header("python email", "utf-8").encode()

server = smtplib.SMTP(smtp_server, 25)
server.set_debuglevel(1)
server.login(from_email, from_email_pwd)
server.sendmail(from_email, [to_email], msg.as_string())
server.quit()

提示错误:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...