1
votes

I'm trying to retrieve new mails from sent mail folder of Gmail using IMAP, but in the sent folder every messages are has the \Seen flag set. So I cannot retrieve the latest messages in the folder.

imap_conn.select("[Gmail]/Sent Mail")

typ, data = imap_conn.search(None,since_date,'UnSeen')

Do anyone have idea for how to retrieve the new mails from sent folder?

2
Did you try your code with a different IMAP server? - user647772
The index numbers I believe are monotonously increasing. Keep track of the index of the last message you read, and retrieve any with a higher index number. - tripleee
If you delete(expunge) a message the index numbers of other messages change, so it would probably be safer to keep track of message UID's or internaldate timestamps - Gryphius

2 Answers

3
votes

For the name to use for your 'Sent Items' folders check:

mail.list()

Make sure you use the extra quotes in your string, e.g.:

imap_conn.select('"[Gmail]/Sent Mail"')  

That worked for me.

0
votes

Although less efficient then Gryphius' answer, you create a custom IMAP flag and then mark all the message you have seen with that custom flag.

Here is an example from SO: javamail: Setting custom flags on imap mail and searching for mails with custom flags