imaplib

IMAP with python to download attachments

谁说胖子不能爱 提交于 2020-07-22 21:34:26
问题 I have a instrument at work that emails me a file containing raw data, I can go into my email and download them easily enough but when I have multiple files (which it sends as multiple emails) it gets a bit tedious. I'm looking at using python and imaplib to login to my email account, search for emails from a known email address within the past day or so and then download any attachments to a directory. So I thought a script might help here. I've setup a gmail account and altered the settings

IMAP with python to download attachments

白昼怎懂夜的黑 提交于 2020-07-22 21:33:30
问题 I have a instrument at work that emails me a file containing raw data, I can go into my email and download them easily enough but when I have multiple files (which it sends as multiple emails) it gets a bit tedious. I'm looking at using python and imaplib to login to my email account, search for emails from a known email address within the past day or so and then download any attachments to a directory. So I thought a script might help here. I've setup a gmail account and altered the settings

Why are the same contents decoded differently according to mail clients?

随声附和 提交于 2020-04-30 06:27:19
问题 My code checks a mailbox, and forwards every mail to another user. But I found out that the same contents are decoded differently according to mail clients(I mean, when sent with account@gmail.com, with account@naver.com, and etc). For example: what I typed, subject: subject content: this is content for mail client 1: 358 2020-04-22 18:12:23,249: run: DEBUG: subject has come as: =?utf-8?B?c3ViamVjdA==?= 359 2020-04-22 18:12:23,249: run: DEBUG: content has come as: dGhpcyBpcyBjb250ZW50Cg== for

How to get pure text from python email using imaplib

Deadly 提交于 2020-01-24 08:48:16
问题 I am wondering how to get pure text form python email using imaplib. What i have so far: from datetime import datetime import imaplib ,email IMAP_SERVER = 'imap.gmail.com' EMAIL_ACCOUNT = "example@gmail.com" PASSWORD = "password" rv, data = M.search(None, "ALL") if rv != 'OK': print("No messages found!") return if data != ['']: # if not empty list means messages exist for num in data[0].split(): rv, data = M.fetch(num, '(RFC822)') #(BODY[HEADER.FIELDS (SUBJECT FROM)]) if rv != 'OK': print(

How to get pure text from python email using imaplib

微笑、不失礼 提交于 2020-01-24 08:48:02
问题 I am wondering how to get pure text form python email using imaplib. What i have so far: from datetime import datetime import imaplib ,email IMAP_SERVER = 'imap.gmail.com' EMAIL_ACCOUNT = "example@gmail.com" PASSWORD = "password" rv, data = M.search(None, "ALL") if rv != 'OK': print("No messages found!") return if data != ['']: # if not empty list means messages exist for num in data[0].split(): rv, data = M.fetch(num, '(RFC822)') #(BODY[HEADER.FIELDS (SUBJECT FROM)]) if rv != 'OK': print(

About IMAP UID with imaplib

我与影子孤独终老i 提交于 2020-01-17 07:59:12
问题 I try to move email from mailbox's gmail to another one, Just curious that UID of each email will change when move to new mailbox ? 回答1: Yes of course the UID is changed when you do move operation. the new UID for that mail will be the next UID from the destination folder. (i.e if the last mail UID of the destination folder is : 9332 , then the UID of the move email will be 9333) Note: UID is changed but the Message-Id will not be changed during any operation on that mail) 回答2: I took a look

Catching imaplib exception (using IMAPClient package) in Python

a 夏天 提交于 2020-01-04 01:59:07
问题 I am using the external library IMAPClient. When the login fails, i see this error : imaplib.error: [AUTHENTICATIONFAILED] Authentication failed. When i try except imaplib.error: i get : AttributeError: 'module' object has no attribute 'error' The documentation of imaplib says that the exception should be IMAP4.error Then why is IMAPClient raising imaplib.error and how do i catch it ? 回答1: The error message you see: imaplib.error: [AUTHENTICATIONFAILED] Authentication failed. is describing

Python IMAP4 select mailbox name contain space character, error

余生颓废 提交于 2020-01-03 02:00:15
问题 I am using Python imaplib.IMAP4 to connect to Google email. Every thing is okay except when I use IMAP4.select() method using a mailbox name that contains a space character. Let's say my mailbox name is "Gama Sutra". When I execute imap.select('[Gmail]/Gama Sutra') it gives me this error: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imaplib.py", line 682, in select typ, dat = self._simple