问题描述
我正在尝试使用python中的smtplib连接到我公司的电子邮件服务器,这是我的代码段:
I am trying to connect with my company's email server using smtplib in python Below is my code snippet:
server = smtplib.SMTP('mail.mycompany.com',25)
server.ehlo()
server.starttls()
server.login('my_email@mycompany.com', 'my_password')
运行代码时,出现以下错误:
When I run my code I get the following error:
smtplib.SMTPException:服务器不支持STARTTLS扩展.
在Google上搜索此错误后,我发现我公司的smtp服务器不支持starttls身份验证,因此我必须从代码中删除 server.starttls()这一行,但是当我删除此行时,出现以下错误:
After searching this error on google i found that my company's smtp server does not support starttls authentication so i have to remove server.starttls() this line from my code but when i remove this line I get following error:
smtplib.SMTPException:服务器不支持SMTP AUTH扩展.
我整天都在搜索这些错误,但没有找到任何解决方案.
I have spent whole day to search these errors but didn't find any solution.
推荐答案
可能不需要登录服务器.当我连接到公司的SMTP服务器时,我不必这样做.因此,您可以尝试执行以下操作:
Probably, you don't need to login to the server. I don't have to when I connect to my corporate SMTP server. So you could try something like:
server = smtplib.SMTP('mail.mycompany.com',25)
server.ehlo()
server.sendmail('my_email@mycompany.com', 'my_email@mycompany.com', msg)
这篇关于Python smtplib登录错误smtplib.SMTPException:服务器不支持STARTTLS扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!