Get Mailbox Information in C#, VB.NET

2017-07-11 06:51:03 Written by  support iceblue
Rate this item
(0 votes)

This article illustrates how to get mailbox information such as the number of messages, the size of mailbox and the unique id of a specific message using Spire.Email component.

Detail steps:

Step 1: Create a pop3 client.

Pop3Client pop = new Pop3Client();

Step 2: Set host, authentication, port and connection protocol.

pop.Host = "outlook.office365.com";
pop.Username = "LeonDavisLD@outlook.com";
pop.Password = "password";
pop.Port = 995;
pop.EnableSsl = true;

Step 3: Connect the pop server.

pop.Connect();

Step 4: Get information of mailbox.

//Get the number of messages
Console.WriteLine("Mailbox message count: " + pop.GetMessageCount());
            
//Get the size of mailbox
Console.WriteLine("Mailbox size: " + pop.GetSize() + " bytes");

//Get the unique id of the first message
Console.WriteLine("Message uid: " + pop.GetMessagesUid(1));

Screenshot:

Get Mailbox Information in C#, VB.NET

Full code:

[C#]
using System;
using Spire.Email.Pop3;

namespace Get_mailbox_information
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create a pop3 client
            using (Pop3Client pop = new Pop3Client())
            {
                //Set host, authentication, port and connection protocol
                pop.Host = "outlook.office365.com";
                pop.Username = "LeonDavisLD@outlook.com";
                pop.Password = "password";
                pop.Port = 995;
                pop.EnableSsl = true;

                //Connect the pop server
                pop.Connect();

                //Get the number of messages
                Console.WriteLine("Mailbox message count: " + pop.GetMessageCount());

                //Get the size of mailbox
                Console.WriteLine("Mailbox size: " + pop.GetSize() + " bytes");

                //Get the unique id of the first message
                Console.WriteLine("Message uid: " + pop.GetMessagesUid(1));
            }
        }
    }
}
[VB.NET]
Imports Spire.Email.Pop3

Namespace Get_mailbox_information
	Class Program
		Private Shared Sub Main(args As String())
			'Create a pop3 client
			Using pop As New Pop3Client()
				'Set host, authentication, port and connection protocol
				pop.Host = "outlook.office365.com"
				pop.Username = "LeonDavisLD@outlook.com"
				pop.Password = "password"
				pop.Port = 995
				pop.EnableSsl = True

				'Connect the pop server
				pop.Connect()

				'Get the number of messages
				Console.WriteLine("Mailbox message count: " + pop.GetMessageCount())

				'Get the size of mailbox
				Console.WriteLine("Mailbox size: " + pop.GetSize() + " bytes")

				'Get the unique id of the first message
				Console.WriteLine("Message uid: " + pop.GetMessagesUid(1))
			End Using
		End Sub
	End Class
End Namespace

Additional Info

  • tutorial_title:
Last modified on Wednesday, 15 September 2021 03:30