如何在没有win32.client

时间:2016-11-08 13:02:40

标签: python linux email delegates imap

我有一个带邮箱的Windows帐户。 在Linux环境中使用Python,我可以使用imaplib帐户凭据访问邮箱中的任何邮件和目录,这样就可以了。

但是现在,我想访问不属于此帐户的委托邮箱,但无法找到。

到目前为止,我使用了来自doc的代码,该代码提供了邮箱中的所有目录。现在我想到另一个邮箱。

我尝试按用户名/委托邮箱更改用户名,但连接失败。

我已经在使用win32.client的Windows环境中看到了一些解决方案,但到目前为止,Linux上没有任何内容。是否有使用imaplib或其他lib的解决方案?

import imaplib
import ConfigParser


def open_connection(verbose=False):
  # Read the config file
  config = ConfigParser.ConfigParser()
  config.read('connection.cfg')

  # Connect to the server
  hostname = config.get('server', 'hostname')
  if verbose: print 'Connecting to', hostname
  connection = imaplib.IMAP4_SSL(hostname)

  # Login to our account
  username = config.get('account', 'username')
  password = config.get('account', 'password')
  if verbose: print 'Logging in as', username
  connection.login(username, password)
  return connection


c = open_connection(verbose=True)
try:
    typ, mailbox_data = c.list()
    for line in mailbox_data:
        print line     
finally:
    try:
        c.close()
    except:
        pass
    c.logout()

配置文件如下:

[server]
hostname: the.hostname

[account]
username: test-account
password: test-password

0 个答案:

没有答案
相关问题