繁体   English   中英

为什么会出现此错误以及如何解决? -Python电子邮件脚本

[英]Why do I get this error and how do I fix it? - Python email script

我不断收到以下错误:

error: [Errno 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

是否有人对导致错误的原因以及如何解决此问题有任何建议?

import smtplib

msg = "\nHello!\nThe following servers have an error........" 
# The /n separates the message from the headers



server = smtplib.SMTP('smtp.gmail.com',587) ## Try 587 or 2525

    server.ehlo()
    server.starttls()

    #Next, log in to the server
    try:
        server.login("useremail", "password")

        print " you are logged into your account"
    except:
        print "Username or password is incorrect" 

    #Send the mail

    try:
        server.sendmail("useremail", "recipient", msg)
        print "Congratulations! Email was sent." 
    except:
        print "email could not send"


        server.close()

也许尝试使用yagmail发送简单的电子邮件,它可以通过默认设置保存:

import yagmail
yagmail.SMTP('username', 'password').send(contents = msg)

您可能必须先使用以下命令安装它:

pip install yagmail # (Python 2) or 
pip3 install yagmail # for Python 3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM