Python使用Gmail Api提取邮件

时间:2016-10-20 15:26:17

标签: python gmail-api

我正在编写Python脚本,它应该从gmail中提取邮件。 我正在使用Gmail Api。代码是:

def get_credentials():
    home_dir = os.path.expanduser('~')
    credential_dir = os.path.join(home_dir, '.credentials')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)
    credential_path = os.path.join(credential_dir,
                                   'gmail-python-quickstart.json')

    store = Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = client.flow_from_clientsecrets(CLIENT_SECRET_FILE, SCOPES)
        flow.user_agent = APPLICATION_NAME
        if flags:
            credentials = tools.run_flow(flow, store, flags)
        else: # Needed only for compatibility with Python 2.6
            credentials = tools.run(flow, store)
        print('Storing credentials to ' + credential_path)
    return credentials

def main():
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    service = discovery.build('gmail', 'v1', http=http)

    results = service.users().threads().list(userId='me').execute()
    result = results.get('threads', [])
    for each in result:
        print(each['snippet']+"\n")

我收到大约200条字符的消息。当我阅读文档时 here。我想使用“有效载荷”和“正文”,但似乎没有这种可能性,只要没有值“有效载荷”。任何想法如何获得完整的消息?

0 个答案:

没有答案