Version: 3.2.1.0
Send, receive, edit, sign/verify and encrypt/decrypt email messages in any .NET application or service. 

Manage Messages With IMAP Code Example

The following example demonstrates moving messages from one folder to another using the PowerTCP Imap component. A session log is created using the Trace event.

< Back to all samples for PowerTCP Mail for .NET

private void buttonMove_Click(object sender, EventArgs e)
{
    try
    {
        //Login to the IMAP server.
        imap1.Login("myserver""myAccount""myPassword");

        //Get headers of messages in the 'Save' mailbox.
        Mailbox box = imap1.Mailboxes["Save"];
        imap1.CurrentMailbox = box;
        box.Get(box.Messages[0], box.Messages[box.Messages.Count - 1],
            ImapMessageSections.Header);

        if (imap1.CurrentMailbox.Messages.Count > 0)
        {
            //Move all messages containing a specific phrase to a new box.
            //These messages will be copied to the new box and deleted from
            //the old box.
            Mailbox newBox = imap1.Mailboxes["GameGroup"];
            foreach (ImapMessage im in box.Messages)
            {
                if (im.Message.Subject.Contains("Game Group"))
                {
                    //Copy to new box. Mark for deletion in old box.
                    im.CopyTo(newBox);
                    box.Set(im, im, ImapFlagModifier.Add, ImapFlags.Deleted);
                }
            }
        }

        //Purge messages marked for deletion.
        box.Purge();

        //Logout
        imap1.Logout();
        MessageBox.Show("DONE!");
    }
    catch (Exception ex)
    {
        //Show error messages.
        MessageBox.Show("Error: " + ex.Message);
    }
}

private void imap1_Trace(object sender, SegmentEventArgs e)
{
    //Log the session.
    textLog.AppendText(e.Segment.ToString());
}