PowerTCP Mail for .NET
Imap Class
Members  Example  See Also  Send comments on this topic.
Dart.PowerTCP.Mail Namespace : Imap Class




The Imap component enables the integration of Internet Message Access Protocol (IMAP) functionality into any .NET application.

Object Model

Imap ClassCertificate ClassTcp ClassMailbox ClassMailboxCollection ClassMailbox Class

Syntax

Visual Basic (Declaration) 
<LicenseProviderAttribute(ImapLicenseProvider)>
Public Class Imap 
   Inherits System.ComponentModel.Component
Visual Basic (Usage)Copy Code
Dim instance As Imap
C# 
[LicenseProviderAttribute(ImapLicenseProvider)]
public class Imap : System.ComponentModel.Component 
Managed Extensions for C++ 
[LicenseProviderAttribute(ImapLicenseProvider)]
public __gc class Imap : public System.ComponentModel.Component 
C++/CLI 
[LicenseProviderAttribute(ImapLicenseProvider)]
public ref class Imap : public System.ComponentModel.Component 

Example

The following example demonstrates logging into an IMAP server, copying read messages to a Deleted mailbox, and deleting them.
Visual BasicCopy Code
Private Sub DoMove()
   ' Demonstrate moving Read messages from "INBOX" to a "Deleted Items" box
   Try
      ' Do synchronous login with AutoList
      Imap1.Login("myServer", "myAccount", "myPassword")

      ' Create Mailbox objects for easier reference
      Dim InboxBox As Mailbox = Imap1.CurrentMailbox ' After Login with AutoList, this will be "INBOX"
      Dim DeletedBox As Mailbox = Imap1.Mailboxes("Deleted Items")

      ' Update Messages Count in "Deleted Items" box
      DeletedBox.Refresh()

      ' Display Messages Count in both boxes
      LabelDisplay.Text = InboxBox.Messages.Count.ToString() + "  " + DeletedBox.Messages.Count.ToString()

      ' Get an array of ImapMessages with just flags
      Dim Messages As ImapMessage() = InboxBox.Get(InboxBox.Messages(0), InboxBox.Messages(InboxBox.Messages.Count-1), ImapMessageSections.Flags)

      ' Copy Read Messages to "Deleted Items" box and Mark them for Deletion
      Dim Msg as ImapMessage
      For Each Msg in Messages
        If Msg.Seen Then 'If Seen flag is set 
           Msg.CopyTo(DeletedBox) ' Copy to "Deleted Items" box
           Msg.Delete = True ' Set deleted flag in "INBOX"
        End If
      Next

      'Permanently Remove Copied Messages from "INBOX"
      InboxBox.Purge()

      'Update Messages Count in "Deleted Items"
      DeletedBox.Refresh()

      'Display new Messages Counts
      LabelDisplay.Text = InboxBox.Messages.Count.ToString() + "  " + DeletedBox.Messages.Count.ToString()

      'Logout from server
      Imap1.Logout()
   
   Catch Ex As Exception
       ' Show MessageBox if error occurs
       MessageBox.Show(Ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
   End Try
End Sub
C#Copy Code
private void DoMove()
{
   //Demonstrate moving Read messages from "INBOX" to a "Deleted Items" box
   try
   {
      //Do synchronous login with AutoList
      imap1.Login("myServer", "myAccount", "myPassword");

      //Create Mailbox objects for easier reference
     Mailbox inboxBox = imap1.CurrentMailbox; //After Login with AutoList, this will be "INBOX"
     Mailbox deletedBox = imap1.Mailboxes["Deleted Items"];

     //Update Messages Count in "Deleted Items" box
     deletedBox.Refresh();

     //Display Messages Count in both boxes
     labelDisplay.Text = inboxBox.Messages.Count.ToString() + "  " + deletedBox.Messages.Count.ToString();

     //Get an array of ImapMessages with just flags
     ImapMessage[] messages = inboxBox.Get(inboxBox.Messages[0], inboxBox.Messages[inboxBox.Messages.Count-1], ImapMessageSections.Flags);

     //Copy Read Messages to "Deleted Items" box and Mark them for Deletion
     foreach (ImapMessage msg in messages)
     {
       if (msg.Seen) //If Seen flag is set
       {
          msg.CopyTo(deletedBox); //Copy to "Deleted Items" box
          msg.Delete = true; //Set deleted flag in "INBOX"
       }
     }

     //Permanently Remove Copied Messages from "INBOX"
     inboxBox.Purge();

     //Update Messages Count in "Deleted Items"
     deletedBox.Refresh();

     //Display new Messages Counts
     labelDisplay.Text = inboxBox.Messages.Count.ToString() + "  " + deletedBox.Messages.Count.ToString();

     //Logout from server
     imap1.Logout();
   }
   catch (Exception ex)
   {
      //Show MessageBox if error occurs
      MessageBox.Show(ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
   }
}

Remarks

The Imap component enables the integration of Internet Message Access Protocol (IMAP) functionality into any .NET application, allowing your application to easily manage Internet mail remotely.

Using the Imap Component

What follows are short descriptions of common features. For a more complete, "walk-through" type description, see the high-level topics or the applicable reference topic.

Easy mailbox management: IMAP mailboxes are represented as Mailbox objects. Multiple Mailbox objects are contained in and managed by the MailboxCollection object. Use this object to add, remove, and modify IMAP mailboxes.

Easy message management: IMAP messages are represented as ImapMessage objects. Set the properties of the ImapMessage to modify message flags. Multiple ImapMessage objects are contained in and managed by the ImapMessageCollection. Use this object to add and modify IMAP messages.

Easy message retrieval: Use the Mailbox.Get method of the Mailbox object to get messages in bulk. Use the ImapMessage.Get method of the ImapMessage object to get a single message.

Easy part retrieval: Use the ImapMessage.GetPart method to get a single part (such as an attachment) from a message without having to download the entire message.

Comprehensive IMAP functionality: Use the Imap component to perform all IMAP functions such as searching, listing, subscribing/unsubscribing, and retrieving message sections.

Advanced attachment decoding: Attachments are decoded "on the fly", eliminating any need for disk access, making your application faster and more efficient. In addition, attachments can be automatically decoded and saved as files, or decoded into MemoryStreams to use within your application.

Synchronous Use: Most applications written with the Imap component will be synchronous, meaning that the application, when calling a synchronous method, will not execute the next line of code until the response is received. Use synchronous methods when the receiving of mail does not have to be transparent to the user.

Asynchronous Use: The Imap component fully supports asynchronous use, meaning that the application, when calling an asynchronous method, will immediately execute the next line of code without waiting for the response from the method. When the response is received, an event will be raised.

Displaying Progress: The Imap.Progress event provides real-time notification of the number of bytes sent or received, both for a single messages and all messages.

Accessing Imap Protocol Communication: The Tcp.Trace and Tcp.RawTrace event enables access to all commands and data sent over the TCP connection.

Retrieving info about the control connection: The TCP control connection is exposed through the Imap.Connection property, allowing access to low-level properties and methods. This can be used to view TCP-level activity, such as the local and remote IP address. Furthermore, you can use the Proxy property of this object to enable automatic communication with proxy servers when getting mail. The Tcp class can't be used on its own without a license for PowerTCP Sockets for .NET.

Sending commands to the server: Any command (including proprietary commands) can be sent to a IMAP server using the Imap.Invoke or Imap.BeginInvoke methods.

Inheritance Hierarchy

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         Dart.PowerTCP.Mail.Imap

Requirements

Target Platforms: Microsoft .NET Framework 2.0

See Also

Documentation Version 3.2
© 2010 Dart Communications. All Rights Reserved.