簡體   English   中英

Python imaplib 登錄失敗

[英]Python imaplib login failed

我正在處理郵件應用程序並遇到 Python imaplib 的一個大問題。

這是我嘗試用來登錄郵件服務器的代碼。

M = imaplib.IMAP4(self.server,int(self.port))
M.login(self.user, self.password)

我正在使用"port 143""useSLL = false"no secure
這是我嘗試登錄服務器時收到的消息。

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:我有另一個郵件應用程序,它在 ruby​​ 上收到電子郵件,它在端口 143 上運行良好,不安全。

任何人都請幫我解決這個問題。 謝謝

改用這個

M = imaplib.IMAP4_SSL(self.server,int(self.port)) M.login(self.user, self.password)

我正在使用imaplib.IMAP4_SSL而不是imaplib.IMAP4這似乎對我有用

我有一個適用於 gmail 和 Outlook 的解決方案

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM