imaplib

IMAP search for email address in the from field

淺唱寂寞╮ 提交于 2019-12-02 09:18:03
问题 I am trying to search and filter my imap mails using python's imaplib. I am running into a quite strange problem with the search command, searching for email addresses in the FROM field. I have the following script, print('search with name') status, results = con.search(None, '(FROM "Shrikant Sharat")') if status == 'OK': if results[0]: mid = results[0].split()[0] print('mail id', mid) print(con.fetch(mid, '(UID BODY[HEADER.FIELDS (FROM)])')) else: print('No results yielded') else: print(

IMAP search for email address in the from field

扶醉桌前 提交于 2019-12-02 08:14:15
I am trying to search and filter my imap mails using python's imaplib. I am running into a quite strange problem with the search command, searching for email addresses in the FROM field. I have the following script, print('search with name') status, results = con.search(None, '(FROM "Shrikant Sharat")') if status == 'OK': if results[0]: mid = results[0].split()[0] print('mail id', mid) print(con.fetch(mid, '(UID BODY[HEADER.FIELDS (FROM)])')) else: print('No results yielded') else: print('unable to search', results) print() print('search with email') status, results = con.search(None, '(FROM

Python imaplib selecting folders

自闭症网瘾萝莉.ら 提交于 2019-12-02 03:41:18
I am bulding a mail client using Django and for extracting emails i'm using imaplib. So far, i can select inbox folder cause in every imap server it's name is "INBOX". But when it comes to selecting other folders like Spam, Sent and others i have troubles because their name come based on account language. For exemple my account is set to russian language and listing mails like this: mail = imaplib.IMAP4_SSL(IMAP) mail.login(USERNAME, PASSWORD) for i in mail.list()[1]: print(i) gives me the following output (utf-7): b'(\\Inbox) "/" "INBOX"' b'(\\Spam) "/" "&BCEEPwQwBDw-"' b'(\\Sent) "/" "

parsing parenthesized list in python's imaplib

帅比萌擦擦* 提交于 2019-12-01 10:47:36
问题 I am looking for simple way to split parenthesized lists that come out of IMAP responses into Python lists or tuples. I want to go from '(BODYSTRUCTURE ("text" "plain" ("charset" "ISO-8859-1") NIL NIL "quoted-printable" 1207 50 NIL NIL NIL NIL))' to (BODYSTRUCTURE, ("text", "plain", ("charset", "ISO-8859-1"), None, None, "quoted-printable", 1207, 50, None, None, None, None)) 回答1: pyparsing's nestedExpr parser function parses nested parentheses by default: from pyparsing import nestedExpr text

Get the Gmail attachment filename without downloading it

江枫思渺然 提交于 2019-11-30 08:47:27
I'm trying to get all the messages from a Gmail account that may contain some large attachments (about 30MB). I just need the names, not the whole files. I found a piece of code to get a message and the attachment's name, but it downloads the file and then read its name: import imaplib, email #log in and select the inbox mail = imaplib.IMAP4_SSL('imap.gmail.com') mail.login('username', 'password') mail.select('inbox') #get uids of all messages result, data = mail.uid('search', None, 'ALL') uids = data[0].split() #read the lastest message result, data = mail.uid('fetch', uids[-1], '(RFC822)') m

Problem deleting emails in gmail using imaplib

柔情痞子 提交于 2019-11-30 05:43:31
问题 I try to remove message from inbox folder and all alright, but when i switched to All Mail folder the removing does not work. expunge() method returns ('OK', [None]) and message was not removed: >>>import imaplib >>>server = imaplib.IMAP4_SSL('imap.gmail.com','993') >>>server.login('likvidator89@gmail.com','Password') >>>server.select('inbox') >>>for i in server.search(None,'all')[1][0].split(): ... print i+"\n"+server.fetch(i,'(BODY[HEADER.FIELDS (Subject)])')[1][0][1] ... # that how i know

I cannot search sent emails in Gmail with Python

核能气质少年 提交于 2019-11-30 03:56:11
I am trying to search for messages in the Sent (actually i care for both) but I only get incoming messages. For the time being i have imap_conn.select() str_after = after.strftime('%d-%b-%Y') typ, msg_ids = imap_conn.search('UTF-8','SINCE',str_after) Which gives equivalent results with this imap_conn.select('INBOX') When I replace INBOX with ALL or SENT I get: command SEARCH illegal in state AUTH, only allowed in states SELECTED w-- Man, the error message is so misleading. What it's really saying is that you have tried to select an invalid folder name hence the search operation fails. To

Python read my outlook email mailbox and parse messages [duplicate]

徘徊边缘 提交于 2019-11-30 00:48:37
Possible Duplicate: Reading e-mails from Outlook with Python through MAPI I am completely new to Python and have been given the task to write a program that connects to my Microsoft Outlook mailbox, goes through all the emails and if the subject has a certain word, then the details of the email time and subject will be saved in variables, as well as the email message body will be parsed and relevant information will be stored in variables. Then this information will be stored in an external server/database. It also needs to be able to monitor any new emails that comes to my mailbox and repeat

How do I reply to an email using the Python imaplib and include the original message?

我是研究僧i 提交于 2019-11-29 21:05:01
I'm currently using imaplib to fetch email messages from a server and process the contents and attachments. I'd like to reply to the messages with a status/error message and links to the resulting generated content on my site if they can be processed. This should include the original message but should drop any attachments (which will be large) and preferably replace them with just their filenames/sizes. Since I'm already walking the MIME message parts, I'm assuming what I need to do is build a new MIME message tree containing a copy of the original message and delete/replace the attachment

Move an email in GMail with Python and imaplib

狂风中的少年 提交于 2019-11-29 20:19:54
I want to be able to move an email in GMail from the inbox to another folder using Python. I am using imaplib and can't figure out how to do it. There is no explicit move command for IMAP. You will have to execute a COPY followed by a STORE (with suitable flag to indicate deletion) and finally expunge . The example given below worked for moving messages from one label to the other. You'll probably want to add more error checking though. import imaplib, getpass, re pattern_uid = re.compile('\d+ \(UID (?P<uid>\d+)\)') def connect(email): imap = imaplib.IMAP4_SSL("imap.gmail.com") password =