As you claim to be new to programming, my best advice is: Always read the documentation.
And maybe you should read a tutorial first.
The documentation provides an example:
import getpass, imaplib
M = imaplib.IMAP4()
M.login(getpass.getuser(), getpass.getpass())
M.select()
typ, data = M.search(None, 'ALL')
for num in data[0].split():
typ, data = M.fetch(num, '(RFC822)')
print 'Message %s\n%s\n' % (num, data[0][3])
M.close()
M.logout()
Have you tried?
Regarding your code:
When you define a for
loop, it should be like:
for x in some_data_set:
x
is a variable, that holds the value of one item at a time (and is accessible only in the for loop body (with one exception, but this is not important here)).
What you are doing is not related to the imaplib module but just wrong syntax.
Btw. .select()
selects a mailbox and only returns the number of messages in the mailbox. I.e. just a scalar value, no sequence you could iterate over:
IMAP4.select([mailbox[, readonly]])
Select a mailbox. Returned data is the count of messages in mailbox (EXISTS response). The default mailbox is 'INBOX'. If the readonly flag is set, modifications to the mailbox are not allowed.
(This is indeed related to imaplib module ;))