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.

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.

694 questions
40
votes
1 answer

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 a normal equal sign but a special symbol. For…
JXITC
  • 1,110
  • 1
  • 13
  • 27
31
votes
4 answers

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 wondering if I can always trust that data[0][1] returns the body of the…
Piotr Czapla
  • 25,734
  • 24
  • 99
  • 122
31
votes
6 answers

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(imap_server) conn.login(imap_user,…
David Vasandani
  • 1,840
  • 8
  • 30
  • 53
30
votes
6 answers

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't know how to display the contents of the…
sadmicrowave
  • 39,964
  • 34
  • 108
  • 180
30
votes
8 answers

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
  • 3,777
  • 4
  • 25
  • 23
28
votes
4 answers

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 know how can I keep the email at its previous stare…
PanosJee
  • 3,866
  • 6
  • 36
  • 49
28
votes
1 answer

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 command error: BAD [b'Could not parse command'] my…
Randy Dellinger
  • 283
  • 1
  • 3
  • 8
23
votes
8 answers

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 below error imaplib.error:…
Mourya Ch
  • 243
  • 1
  • 2
  • 8
18
votes
3 answers

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's going to be in Django. Right now my script logs…
HankSmackHood
  • 4,673
  • 7
  • 29
  • 30
18
votes
1 answer

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 generated content on my site if they can be…
Tom
  • 42,844
  • 35
  • 95
  • 101
15
votes
1 answer

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 other folders like Spam, Sent and others i have…
15
votes
1 answer

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('myemail@gmail.com', 'mypassword') mail.select("inbox") # returns ('OK', [b'12009']) This all seems to work nicely,…
pandita
  • 4,739
  • 6
  • 29
  • 51
14
votes
3 answers

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 don't want it to block?
okoboko
  • 4,332
  • 8
  • 40
  • 67
14
votes
4 answers

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:\PYTHONPROJECTS" # where you will save attachments user =…
kiriloff
  • 25,609
  • 37
  • 148
  • 229
13
votes
2 answers

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',…
user2884042
  • 241
  • 1
  • 2
  • 7
1
2 3
46 47