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'])
Although
IMAPClientis a lot easier than usingimaplib, 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:
And the BODY via:
However, what’s generally easier is to do:
Just be wary of where the payload includes attachments or is multipart…