MailBee.NET Objects 4.0

Imap Class

Provides properties and methods for connecting to an IMAP4 server, downloading, searching, and managing folders and e-mail messages in a user account.

For a list of all members of this type, see Imap Members.

System.Object
   MailBee.InternalUse.LengthyTaskEventSink
      MailBee.InternalUse.SocketEventSink
         MailBee.InternalUse.SessionProtocolEventSink
            MailBee.InternalUse.ImapEventSink
               MailBee.ImapMail.Imap

public class Imap : ImapEventSink, IComponent, IDisposable

Thread Safety

Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.

Remarks

You can perform the following operations using this class:

Example

This sample connects to an IMAP4 server, logs in using the most secure method supported by this server, downloads envelopes for the last 10 messages in the inbox, and prints From:, To:, and Subject: field values for every message into Console, newer messages first.

[C#]
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Connect("mail.somecompany.com");
        imp.Login("jdoe@somecompany.com", "secret");
        imp.SelectFolder("INBOX");

        string range;

        // Does the inbox contain at least 10 mails?
        if (imp.MessageCount >= 10)
        {
            // We'll get last 10 mails.
            range = (imp.MessageCount - 9).ToString() + ":" + "*";
        }
        else
        {
            // We'll get all mails.
            range = Imap.AllMessages;
        }

        // Get envelopes for the specified messages.
        EnvelopeCollection envelopes = imp.DownloadEnvelopes(range, false);

        // Make newer messages be displayed first.
        envelopes.Reverse();

        foreach (Envelope env in envelopes)
        {
            Console.WriteLine("Message #" + env.MessageNumber);
            Console.WriteLine("From: " + env.From.ToString());
            Console.WriteLine("To: " + env.To.ToString());
            Console.WriteLine("Subject: " + env.Subject);
            Console.WriteLine();
        }

        // Disconnect from the server.
        imp.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    Sub Main(ByVal args As String())
        Dim imp As New Imap

        ' Connect to the server, login and select inbox.
        imp.Connect("mail.somecompany.com")
        imp.Login("jdoe@somecompany.com", "secret")
        imp.SelectFolder("INBOX")

        Dim range As String

        ' Does the inbox contain at least 10 mails?
        If imp.MessageCount >= 10 Then
            ' We'll get last 10 mails.
            range = (imp.MessageCount - 9).ToString() & ":" & "*"
        Else
            ' We'll get all mails.
            range = Imap.AllMessages
        End If

        ' Get envelopes for the specified messages.
        Dim envelopes As EnvelopeCollection = imp.DownloadEnvelopes(range, False)

        ' Make newer messages be displayed first.
        envelopes.Reverse()

        For Each env As Envelope In envelopes
            Console.WriteLine("Message #" & env.MessageNumber)
            Console.WriteLine("From: " & env.From.ToString())
            Console.WriteLine("To: " & env.To.ToString())
            Console.WriteLine("Subject: " & env.Subject)
            Console.WriteLine()
        Next

        ' Disconnect from the server.
        imp.Disconnect()
    End Sub
End Module

Requirements

Namespace: MailBee.ImapMail

Assembly: MailBee.NET (in MailBee.NET.dll)

See Also

Imap Members | MailBee.ImapMail Namespace