In VB.NET, the code might look like this:
''# connect and log in
Dim imap As New Imap
imap.Connect("imap.gmail.com", 993, Nothing, ImapSecurity.Implicit)
imap.Login(username, password)
''# go to inbox
imap.SelectFolder("Inbox")
''# serch for e-mails that contain the expected text – get list of their IDs
Dim messages As ImapMessageCollection = imap.Search(_
ImapListFields.UniqueId, _
ImapSearchParameter.Body("Congratulations you have sold your product"), _
ImapSearchParameter.HasFlagsNoneOf(ImapMessageFlags.Seen) _
)
''# download each of the e-mails found,
''# retrieve its body and check whether it is the message you need
For Each info As ImapMessageInfo In messages
Dim mail As MailMessage = imap.GetMailMessage(info.UniqueId)
Dim mailText As String = mail.BodyText
''# search the string here, extract data you need and do what you need with it
Next
imap.Disconnect()