Questions tagged [imaplib]

Python module to provide an Internet Message Access Protocol (IMAP) client implementation. This protocol lets you access mail folders stored on a central mail server, as if they were local.

imaplib
Filter by
Sorted by
Tagged with
45 votes
1 answer
14k views

How to understand the equal sign '=' symbol in IMAP email text?

I am currently using Python imaplib to process email text. I use fetch command to fetch the raw data email from GMail server. However, I found one thing really tricky - the equal sign '='. It is not ...
JXITC's user avatar
  • 1,170
33 votes
4 answers
91k views

How to fetch an email body using imaplib in python?

I'd like to fetch the whole message from IMAP4 server. In python docs if found this bit of code that works: >>> t, data = M.fetch('1', '(RFC822)') >>> body = data[0][1] I'm ...
Piotr Czapla's user avatar
  • 26.1k
31 votes
6 answers
84k views

Get only NEW Emails imaplib and python

This is a smaller portion of a bigger project. I need to only get unread emails and a parse their headers. How can I modify the following script to only get unread emails? conn = imaplib.IMAP4_SSL(...
David Vasandani's user avatar
31 votes
8 answers
43k views

Move an email in GMail with Python and imaplib

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.
Dan's user avatar
  • 3,857
30 votes
6 answers
68k views

python imaplib to get gmail inbox subjects titles and sender name

I'm using pythons imaplib to connect to my gmail account. I want to retrieve the top 15 messages (unread or read, it doesn't matter) and display just the subjects and sender name (or address) but don'...
sadmicrowave's user avatar
  • 40.5k
28 votes
4 answers
13k views

Fetch an email with imaplib but do not mark it as SEEN

I want to parse some emails from a user 's inbox but when I do: typ, msg_data = imap_conn.fetch(uid, '(RFC822)') It marks the email as SEEN or read. This is not the desired functionality. Do you ...
PanosJee's user avatar
  • 3,866
28 votes
1 answer
27k views

Unable to retrieve gmail messages from any folder other than inbox (Python3 issue)

Update: my code works under python 2.6.5 but not python 3 (I'm using 3.4.1). I'm unable to search for messages in the "All Mail" or "Sent Mail" folders - I get an exception: imaplib.error: SELECT ...
Randy Dellinger's user avatar
23 votes
9 answers
39k views

reading gmail is failing with IMAP

I am running a cron job which executes the python script for reading gmail (2 min interval). I have used imaplib for reading the new mails. This was working fine until yesterday. Suddenly its throwing ...
Mourya Ch's user avatar
  • 253
19 votes
3 answers
19k views

use imaplib and oauth for connection with Gmail

I want to use Oauth to connect to Gmail in Python. Right now I've got the xoauth.py script from Google (link), and generating a token works all fine, but how can I then use that in another script? It'...
HankSmackHood's user avatar
18 votes
1 answer
12k views

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

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 ...
Tom's user avatar
  • 43.7k
15 votes
1 answer
6k views

Reading emails with imaplib - "Got more than 10000 bytes" error

I'm trying to connect to my gmail account with imaplib: import imaplib mail = imaplib.IMAP4_SSH('imap.gmail.com') mail.login('[email protected]', 'mypassword') mail.select("inbox") # returns ('OK', [...
pandita's user avatar
  • 4,879
15 votes
2 answers
28k views

python 3 smtplib exception: 'SSL: WRONG_VERSION_NUMBER' logging in to outlook

The following code in python 3 raises an error on my computer, and I don't know how to log in properly: import smtplib connection = smtplib.SMTP('smtp-mail.outlook.com', 587) connection.ehlo() ...
user2884042's user avatar
15 votes
4 answers
28k views

Python imaplib fetch body emails gmail

I read this already and wrote this script to fetch body for emails in some mail box which title begins with '$' and is sent by some sender. import email, getpass, imaplib, os detach_dir = "F:\...
kiriloff's user avatar
  • 26k
15 votes
1 answer
23k views

Python imaplib selecting folders

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 ...
Гриша Кушнир's user avatar
14 votes
3 answers
8k views

Does Python's imaplib let you set a timeout?

I'm looking at the API for Python's imaplib. From what I can tell, there is no way to setup a timeout like you can with smtplib. Is that correct? How would you handle a host that's invalid if you ...
okoboko's user avatar
  • 4,422
13 votes
4 answers
11k views

Get the Gmail attachment filename without downloading it

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 ...
mopsiok's user avatar
  • 565
12 votes
2 answers
29k views

imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED

def connect_imap(): m = imaplib.IMAP4_SSL("imap.gmail.com", 993) print("{0} Connecting to mailbox via IMAP...".format(datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S"))) details = ...
user5319825's user avatar
12 votes
1 answer
35k views

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

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 ...
user1650464's user avatar
12 votes
4 answers
8k views

Access Gmail Imap with OAuth 2.0 Access token

I am using Google's Oauth 2.0 to get the user's access_token, but I dont know how to use it with imaplib to access inbox.
Kuldeep Kapade's user avatar
12 votes
1 answer
9k views

Parsing Multipart emails in python and saving attachments

I am pretty new to python and I am trying to parse email from gmail via python's imaplib and email. It is working pretty well but I am having issues with email attachments. I would like to parse out ...
ajt's user avatar
  • 1,351
11 votes
5 answers
12k views

I cannot search sent emails in Gmail with Python

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, ...
PanosJee's user avatar
  • 3,866
11 votes
1 answer
25k views

How to get csv attachment from email and save it

I am trying to get the attachment from an email and save it to a specific folder with the original file name. The email is very basic and does not have much to it other than the attachment. The file ...
CircuitB0T's user avatar
11 votes
2 answers
5k views

Listen for incoming emails in real time

Most IMAP email clients have the ability to receive emails automatically in real time, without refreshing on a fixed interval. This is because the email client keeps a connection open to the server, ...
Billy's user avatar
  • 1,235
10 votes
1 answer
5k views

Why can't I login to an imap server twice in Python

As the error message below states, I cannot log in because I'm in state LOGOUT and not in state NONAUTH. How do I get from LOGOUT to NONAUTH? Example below (obviously the login credentials are faked ...
dl__'s user avatar
  • 4,560
9 votes
2 answers
23k views

EOF Error in Imaplib

I am programming a python applet that watches the unread count of the email boxes for my workplace, and ran into an EOF error when I try to use any imaplib methods after the applet sits idle for about ...
Cavendish Owl's user avatar
9 votes
2 answers
6k views

Python/imaplib - How to get messages' labels?

I'm using imaplib for my project because I need to access gmails accounts. Fact: With gmail's labels each message may be on an arbitrary number of folders/boxes/labels. The problem is that I would ...
jpaires's user avatar
  • 355
9 votes
3 answers
13k views

Parsing IMAP responses in python

I am using imaplib to work with imap in python, however it looks like it doesn't have means to parse the details of IMAP responses. For example, query like: msgdata = connection.fetch(num, "(BODY....
StasM's user avatar
  • 10.7k
9 votes
1 answer
3k views

Imaplib: how to delete an email from Gmail?

I am trying to do something as simple as moving an email from inbox to trash using the imaplib of python. However, I am having some problems and I don't know how to solve them. After connect and ...
Esabe's user avatar
  • 1,971
8 votes
2 answers
22k views

Extract information from Gmail with Python

I have come through solutions to extract useful information from selected received emails in Gmail mailbox. Aim in this example is to fetch all mails sent from a newsletter providing monthly prices ...
kiriloff's user avatar
  • 26k
8 votes
2 answers
20k views

Python IMAP Search from or to designated email address

I am using this with Gmail's SMTP server, and I would like to search via IMAP for emails either sent to or received from an address. This is what I have: mail = imaplib.IMAP4_SSL('imap.gmail.com') ...
Tech163's user avatar
  • 4,246
8 votes
3 answers
6k views

Script to move messages from one IMAP server to another

Our office uses 2 IMAP servers for e-mail, one is the incoming server and holds the recent e-mails and the other is an archive server. We mainly use Outlook 2010 and our current process is to ...
j_syk's user avatar
  • 6,571
8 votes
1 answer
5k views

Creating a Draft message in Gmail using the imaplib in Python

I want to write a python module that sends data to a draft message in a G-mail account. I have written a script about two weeks ago that worked perfectly using imaplib. A simplified example of my ...
Mink's user avatar
  • 438
8 votes
1 answer
2k views

Why are replies to my SMTP-sent gmail messages not threaded?

I'm sending lots of similar emails out via SMTP using the following Python snippet: def send(from_, to, body): server = smtplib.SMTP('smtp.gmail.com:587') server.ehlo() server.starttls() ...
Michael Gundlach's user avatar
7 votes
4 answers
10k views

Problem deleting emails in gmail using imaplib

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: >&...
Michael Girnyak's user avatar
7 votes
3 answers
14k views

TypeError: initial_value must be str or none, not bytes in python 3?

Here is my code: import imaplib from email.parser import HeaderParser conn = imaplib.IMAP4_SSL('imap.gmail.com') conn.login('[email protected]', 'password') conn.select() conn.search(None, 'ALL') ...
user avatar
7 votes
4 answers
24k views

How to create an email and send it to specific mailbox with imaplib

I am trying to use python's imaplib to create an email and send it to a mailbox with specific name, e.g. INBOX. Anyone has some great suggestion :).
vernomcrp's user avatar
  • 3,529
7 votes
2 answers
10k views

Fetching multiple IMAP messages at once

The examples I've seen about loading emails over IMAP using python do a search and then for each message id in the results, do a query. I want to speed things up by fetching them all at once.
Dan Benamy's user avatar
7 votes
3 answers
8k views

Python Message' object has no attribute 'get_body

I'm trying to search email body but facing some issues: #!/usr/local/bin/python3 from email.message import EmailMessage import email import imaplib import re import sys import logging import base64 ...
user avatar
7 votes
2 answers
13k views

Python imaplib search email with date and time

I'm trying to read all emails from a particular date and time. mail = imaplib.IMAP4_SSL(self.url, self.port) mail.login(user, password) mail.select(self.folder) since = datetime.strftime(since, '%d-%b-...
Anoop's user avatar
  • 2,778
7 votes
1 answer
14k views

python imaplib search with multiple criteria

I'm trying to use the search function and am running into an issue. I can download all attachments from a gmail account and sort them according to the file extension. I have all of that code working ...
Jeff's user avatar
  • 103
7 votes
3 answers
10k views

How to efficiently parse emails without touching attachments using Python

I'm playing with Python imaplib (Python 2.6) to fetch emails from GMail. Everything I fetch an email with method http://docs.python.org/library/imaplib.html#imaplib.IMAP4.fetch I get whole email. I ...
Viet's user avatar
  • 18.1k
6 votes
3 answers
10k views

Python email quoted-printable encoding problem

I am extracting emails from Gmail using the following: def getMsgs(): try: conn = imaplib.IMAP4_SSL("imap.gmail.com", 993) except: print 'Failed to connect' print 'Is your internet ...
timbo's user avatar
  • 13.8k
6 votes
1 answer
5k views

Mark a *single* IMAP message as unread

I'm trying to manipulate IMAP flags on a single message to mark it unread, after fetching all the "UNREAD" messages and then iterating through them and fetching them. I'm not entirely sure how to ...
Thomas Ward's user avatar
  • 2,712
6 votes
1 answer
7k views

Python 3: Move email to trash by uid (imaplib)

I want to move an email from my inbox to the trash folder, I do not want the email permanently deleted, I want it to go through the process of waiting 30 days in the trash to be permanently deleted. ...
0_jump's user avatar
  • 389
6 votes
3 answers
3k views

imaplib2 : imap.gmail.com handler BYE response: System error

I'm renovating a python script that checks IMAP for new emails and sends a push notification if there's a new email. The problem is that every few hours I'm getting a crash. At first I couldn't really ...
Segev's user avatar
  • 19.2k
5 votes
1 answer
6k views

using imaplib to fetch only the headers of the emails?

Hi i was wondering if someone can help me on extracting the headers of my emails in gmail. I have this code: import imaplib M = imaplib.IMAP4('imap.gmail.com') M.login('myusername', 'mypassword') M....
user avatar
5 votes
2 answers
13k views

Reading unread emails using python script

I am trying to read all the unread emails from the gmail account. The above code is able to make connection but is unable to fetch the emails. I want to print the content of each email. I am getting ...
Aniket Bote's user avatar
  • 3,514
5 votes
3 answers
43k views

How to read email content in Python 3

I've tried many code to access and read email content, for example, about Gmail i only can do authentication and with Outlook i have code that can read email but it's encrypted...but now it only ...
Ricardo91's user avatar
5 votes
1 answer
9k views

How to connect with Python IMAP4_SSL and self-signed server SSL cert?

I'm using python3 and imaplib to connect to an Exchange server. The Exchange server uses a self-signed certificate created for the hostname 'my.server.fqdn'. After a recent OS upgrade on my ...
Koko's user avatar
  • 459
5 votes
4 answers
4k views

imaplib/gmail how to download full message (all parts) while not marking read [duplicate]

I inadvertently marked all the messages in my inbox as read with this python statement: status, data = conn.uid('fetch', fetch_uids, '(RFC822)') But I was able to walk through all the parts of the ...
nomadicME's user avatar
  • 1,399

1
2 3 4 5
14