How to obtain account information

This tutorial illustrates how to obtain Mailbox information with a few lines of code in Ultimate IMAP Component. Other examples for SMTP and POP3 can also be found at SMTP blog and POP3 blogThe simplest way to obtain information about a specified mailbox is using the GetMailboxInfo method. You only need to pass the mailbox name to the method. It returns a Mailbox object containing information about the mailbox you have requested.

If you want to obtain mailbox information of a Gmail IMAP account, please ensure the imap client connection is enabled on the GMAIL account setting page as shown in this picture:

IMAP Settings in GMAIL

The following steps illustrate how to obtain mailbox information with Ultimate mail library:

  1. Add using directives to your code to create aliases for existing ComponentSoft namespaces and avoid having to type the fully qualified type names. The code looks similar to the following:


    C#

    using ComponentSoft.Net;
    using ComponentSoft.Net.Mail;

    VB.NET

    Imports ComponentSoft.Net
    Imports ComponentSoft.Net.Mail

  2. Create a new instance of the ImapClient class and call the Connect methods. The code looks similar to the following:
    C#

    // Create a new instance of the ImapClient class.
    ImapClient client = new ImapClient();
    // Connect to the server.
    client.Connect("myserver");
    // Or you can specify the IMAP port with
    // client.Connect("myserver", 143);
    // Login to the server.
    client.Authenticate("user", "password");
    // Get information about the INBOX mailbox.
    Mailbox m = client.GetMailboxInfo("INBOX");
    Console.WriteLine(
    "The number of recent messages: " + m.RecentMessages);
    Console.WriteLine(
    "The number of new unseen messages messages: " + m.NewUnseenMessages);
    // Close the connection.
    client.Disconnect();

    VB.NET

    ' Create a new instance of the ImapClient class.
    Dim client As New ImapClient()
    ' Connect to the server.
    client.Connect("myserver")
    ' Or you can specify the IMAP port with
    ' client.Connect("myserver", 143);
    ' Login to the server.
    client.Authenticate("user""password")
    ' Get information about the INBOX mailbox.
    Dim m As Mailbox = client.GetMailboxInfo("INBOX")
    Console.WriteLine("The number of recent messages: " & m.RecentMessages)
    Console.WriteLine("The number of new unseen messages messages: " & m.NewUnseenMessages)
    ' Close the connection.
    client.Disconnect()

Now you have successfully connected to the IMAP server and obtained information about the mailbox on the server. This is just a basic steps to manipulate mailboxes and messages. For more advanced tutorials, you can download the Ultimate Mail Library and take a look at the documentation as well as a number of carefully designed sample projects.