[英]Python imaplib login failed
I'm working on mail application and encountering a big problem with Python imaplib.我正在处理邮件应用程序并遇到 Python imaplib 的一个大问题。
Here is the code that I try to use to login to mail server.这是我尝试用来登录邮件服务器的代码。
M = imaplib.IMAP4(self.server,int(self.port))
M.login(self.user, self.password)
I'm using "port 143"
, "useSLL = false"
, no secure
.我正在使用"port 143"
, "useSLL = false"
, no secure
。
And here is the message that I receive when trying to login to server.这是我尝试登录服务器时收到的消息。
DEBUG:root:Login failed.
Traceback (most recent call last):
File "/opt/splunk/etc/apps/IMAPmailbox/bin/get_imap_email.py", line 347, in getMail
M.login(self.user, self.password)
File "/opt/splunk/lib/python2.7/imaplib.py", line 520, in login
raise self.error(dat[-1])
error: Login failed.
None
Traceback (most recent call last):
File "/opt/splunk/etc/apps/IMAPmailbox/bin/get_imap_email.py", line 724, in <module>
parseArgs()
File "/opt/splunk/etc/apps/IMAPmailbox/bin/get_imap_email.py", line 716, in parseArgs
imapProc.getMail()
File "/opt/splunk/etc/apps/IMAPmailbox/bin/get_imap_email.py", line 352, in getMail
raise LoginError('Could not log into server: %s with password provided' % self.server)
__main__.LoginError: Could not log into server: (my server) with password provided
p/s: I have another mail application which get emails throw imap on ruby and it's working fine with port 143 no secure. p/s:我有另一个邮件应用程序,它在 ruby 上收到电子邮件,它在端口 143 上运行良好,不安全。
Anyone please help me to solve this problem.任何人都请帮我解决这个问题。 Thanks谢谢
Use this instead改用这个
M = imaplib.IMAP4_SSL(self.server,int(self.port)) M.login(self.user, self.password)
I am using imaplib.IMAP4_SSL
instead of imaplib.IMAP4
and this seems to work for me我正在使用imaplib.IMAP4_SSL
而不是imaplib.IMAP4
这似乎对我有用
I got a solution which work for both gmail and Outlook我有一个适用于 gmail 和 Outlook 的解决方案
def connect(self, username, password): if self.tls: self.server.starttls() def connect(self, username, password): if self.tls: self.server.starttls()
if(self.hostname == 'imap.outlook.com'):
imap_server = "outlook.office365.com"
self.server = self.transport(imap_server, self.port)
self.server = imaplib.IMAP4_SSL(imap_server)
(retcode, capabilities) = self.server.login(username,password)
self.server.select('inbox')
else:
typ, msg = self.server.login(username, password)
if self.folder:
self.server.select(self.folder)
else:
self.server.select()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.