socket.error: [Errno 10060]: Unable send an email from outlook using python

socket.error: [Errno 10060]: Unable send an email from outlook using python

我下面的代码可以正常工作几个月。现在,它给我下面的错误,

socket.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

        sender = 'myemail@email.com'
        receiver = ['myemail@email.com',]
        msg = MIMEMultipart()

        print("Sending an email to {} ...".format(receiver))

        msg['From'] = sender
        msg['To'] = ", ".join(receiver)
        msg['Subject'] = 'Automation Testing'

        body = 'Hello,' 
        msg.attach(MIMEText(body, 'plain'))
        # filename = 'Fidelity-Success' + timestamp + '.png'
        attachment = open('C:\mydrive\{}'.format(filename), 'rb')

        part = MIMEBase('application', 'octet-stream')
        part.set_payload((attachment).read())
        # part.set_payload((attachment).read())
        encoders.encode_base64(part)
        part.add_header('Content-Disposition', "attachment; filename= " + filename)

        msg.attach(part)

        server = smtplib.SMTP('mail.email.com', 587, timeout=120)
        #server = smtplib.SMTP_SSL('mail.email.com', 93, timeout=120)

        server.starttls()
        server.login(sender, "password")
        text = msg.as_string()
        server.sendmail(sender, receiver, text)
        # server.quit()
        time.sleep(4)
        print("Email sent.")

我尝试了各种端口和超时,但没有成功。我不知道为什么它突然停止工作了。

非常感谢任何帮助。

出现网络问题。我只需要添加邮件和 smtp 服务器的 IP。

临时修复:运行 在管理员模式下在命令提示符下执行以下命令:

route add 'IP of mail server' mask 255.255.255.255 'default gateway of your machine'
route add 'IP of smtp server' mask 255.255.255.255 'default gateway of your machine'

永久修复:要求网络团队将邮件服务器的 IP 添加到拆分隧道。