How can I retrieve a specific e-mail based on a certain text contained in the message ? For example how Gmail search works. If you search for a specific text, which is in the e-mail, then the Gmail will retrieve the message that is associated with the text. Preferably without any looping.
Share
You’re looking for the
SearchMailBoxmethod. Here’s a simple example expecting that you have the IMAP client (in this case, theIMAPClientvariable of theTIdIMAP4type) already connected to the Gmail server. For those looking for how to do so, take a look for instance atthis postand put this code inside thetry..finallyblock nearIMAPClient.ConnectandIMAPClient.Disconnect.Here’s the quick implementation of the IMAP search for UTF-8 charset. It uses interposed class due to protected
ParseSearchResultmethod:And the usage: