How to mark messages

Jun 9, 2009 at 6:56 PM
Edited Jun 9, 2009 at 7:04 PM

Basically I have a mailbox set up that people send emails to. When a new message comes in, I want the program to read the email and parse out the infomation it wants and puts it into a SQL database.

My program runs every once in a every 30 minutes, Question on once email is read I do not want to read that email (is there  a way to either flag or delete the email?) See my comments in green below


Dim objIMAPConnect as New Koolwired.Imap.ImapConnect("")

Dim objIMAPCommand AS New Koolwired.Imap.ImapCommand(objIMAPConnect)
Dim objIMAPAuthenticate AS New Koolwired.Imap.ImapAuthenticate(objIMAPConnect,"userid","password")

Dim objIMAPMailBox AS Koolwired.Imap.ImapMailbox = objIMAPCommand.Select("Inbox")

objIMAPMailBox = objIMAPCommand.Fetch(objIMAPMailBox)

For i AS Integer= 0 TO objIMAPMailBox.Messages.Count -1<font size="2"></font>

Dim strSubject AS String

strSubject = objIMAPMailBox.Messages(i).Subject

IF strSubject .Contains("@@") = True Then

'IF Subject contains "@@" then either flag this message or mark it deleted so we

'do not process it again.

End If




Catch ex As Exception



End Sub

Jun 10, 2009 at 7:29 AM

On the class ImapMailboxMessage there is a property Flags look at that to determine what to do with the message.

To set the flag take a look at the ImapCommand class. There you will find different Set methods (SetDeleted, SetSeen, etc).

A short example in C#:

ImapConnect connection = new ImapConnect(serverIp);
ImapCommand command = new ImapCommand(connection);
ImapAuthenticate authenticate = new ImapAuthenticate(connection, username, password);

ImapMailbox mailbox = command.Select(myFolder);
mailbox = command.Fetch(mailbox);

if (mailbox != null && mailbox.Messages != null)
   foreach (ImapMailboxMessage message in mailbox.Messages)
      if (message.Flags.Deleted) continue;

      //set the flag
      command.SetDeleted(message.ID, true);
      //to really delete the message



Hope this will point you in the right direction.

Jun 10, 2009 at 1:12 PM

Thank you.