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 8770499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:34:09+00:00 2026-06-13T17:34:09+00:00

Using IMAPClient how do I view the message body and the senders email address?

  • 0

Using IMAPClient how do I view the message body and the senders email address?

server = IMAPClient(imap_server, use_uid=True, ssl=ssl)
server.login(imap_user, imap_password)

print 'login successful'

select_info = server.select_folder('INBOX')
print '%d messages in INBOX' % select_info['EXISTS']

messages = server.search(['NOT DELETED'])
print "%d messages that aren't deleted" % len(messages)

print
print "Messages:"
response = server.fetch(messages, ['FLAGS', 'RFC822.SIZE'])
for msgid, data in response.iteritems():
    print '   ID %d: %d bytes, flags=%s' % (msgid,
                                            data['RFC822.SIZE'],
                                            data['FLAGS'])
  • 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-06-13T17:34:09+00:00Added an answer on June 13, 2026 at 5:34 pm

    Although IMAPClient is a lot easier than using imaplib, it’s still useful to know about the IMAP protocol

    (Note, I’ve picked an arbitrary single email id to work with)

    You can get the FROM via:

    server.fetch([456], ['BODY[HEADER.FIELDS (FROM)]'])
    # {456: {'BODY[HEADER.FIELDS (FROM)]': 'From: Facebook <register+mr4k25sa@facebookmail.com>\r\n\r\n', 'SEQ': 456}}
    

    And the BODY via:

    server.fetch([456], ['BODY[TEXT]'])
    # {456: {'BODY[TEXT]': "Hey Jon,\r\n\r\nYou recently entered a new contact email [snip]", 'SEQ': 456}}
    

    However, what’s generally easier is to do:

    import email
    m = server.fetch([456], ['RFC822'])
    msg = email.message_from_string(m[456]['RFC822'])
    print msg['from']
    # Facebook <register+mr4k25sa@facebookmail.com>
    from email.utils import parseaddr
    print parseaddr(msg['from'])
    # ('Facebook', 'register+mr4k25sa@facebookmail.com')
    print msg.get_payload()
    # content of email...
    

    Just be wary of where the payload includes attachments or is multipart…

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

Sidebar

Related Questions

I am retrieving emails from my email server using IMAPClient (Python), by checking for
I'm using python's IMAPClient to retrieve email messages from IMAP server. One of the
I am using the external library IMAPClient. When the login fails, i see this
I'm using MailSystem.NET and trying to delete a message from the server. The problem
I'm attempting to connect to our exchange server using Mail::IMAPClient but a script that
Using SQL Server 2008 R2 we are looking for a way to select the
I keep getting a NO LOGIN failed message when trying to connect to the
I have written some code in Python using imapclient and poplib to collect my
Using PyGtk's IconView, I can set the icons to be reorderable by calling gtk.IconView.set_reorderable(True)
Using SQL Server 2000 Table1 Id date --- ---------- 001 23/01/2012 002 25/01/2012 003

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.