Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6764271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:34:27+00:00 2026-05-26T14:34:27+00:00

hi everyone I am using a script which involves: import oauth2 as oauth import

  • 0

hi everyone I am using a script which involves:

import oauth2 as oauth
import oauth2.clients.imap as imaplib
import email
conn = imaplib.IMAP4_SSL('imap.googlemail.com')
conn.debug = 4 

# This is the only thing in the API for impaplib.IMAP4_SSL that has 
# changed. You now authenticate with the URL, consumer, and token.
conn.authenticate(url, consumer, token)

# Once authenticated everything from the impalib.IMAP4_SSL class will 
# work as per usual without any modification to your code.
conn.select('[Gmail]/All Mail')

response, item_ids = conn.search(None, "SINCE", "01-Jan-2011")
item_ids = item_ids[0].split()

# Now iterate through this shit and retrieve all the email while parsing
# and storing into your whatever db.

for emailid in item_ids:
    resp, data = conn.fetch(emailid, "(RFC822)") 
    email_body = data[0][1] 
    mail = email.message_from_string(email_body) 

My current problem is that I can’t seem to be able to retrieve the body of the mail instance. I am able to see the content of the email by printing it or mail.as_string() but then even with mail.keys() and mail.values() i am actually unable to see the mail’s content (the main message).

What is wrong with this email lib API? (or rather what am I doing wrong)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:34:28+00:00Added an answer on May 26, 2026 at 2:34 pm

    From email docs:

    You can pass the parser a string or a file object, and the parser will
    return to you the root Message instance of the object structure.

    For simple, non-MIME messages the payload of this root object will
    likely be a string containing the text of the message. For MIME
    messages, the root object will return True from its is_multipart()
    method, and the subparts can be accessed via the get_payload() and
    walk() methods.

    So use get_payload() or if the message is multipart then call walk() method and then use get_payload() on a desirable subpart.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following script which I am using in an intranet environment: function
Aloha everyone, I have created a small bash shell script which I wanted to
I hope not everyone is using Rational Purify. So what do you do when
In class, we are all 'studying' databases, and everyone is using Access. Bored with
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Greetings everyone! I programmed GUI Application using Java Swing under Windows. Under windows everything
Hey everyone, I want to start using Scheme and I have two questions. First,
I'm using a DateTime in C# to display times. What date portion does everyone
When I'm online it seems that everyone has agreed that using the exclusive locking
Hey everyone. The following is the code that I am using to play random

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.