Asynchronously gets folder information without selecting it. Only
TotalMessages,
RecentMessages,
NotSeenMessages,
UidValidity, and
UidNext properties
of the
Folder class are available after calling this method.
public Task<Folder> GetFolderInfoAsync(
string folder,
object userState = null
)
Public Function GetFolderInfoAsync( _
ByVal folder As String, _
ByVal userState As Object = null _
) As Task(Of Folder)
public:
Task<Folder> GetFolderInfoAsync(
String^ folder,
Object^ userState = null
);
Parameters
- folder
- The folder name to get information about.
- userState
- A user-provided object that identifies this particular asynchronous operation.
Return Value
An object that references the asynchronous operation.
Get information of an existing mailboxes asynchronously (Task-based asynchronous approach).
using System;
using ComponentPro;
using ComponentPro.Net.Mail;
...
// Create a new instance of the Imap class.
Imap client = new Imap();
// 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");
// ...
// Obtain information about the 'INBOX' mailbox.
Folder folder = await client.GetFolderInfoAsync("INBOX");
// ...
Console.WriteLine("The number of recent messages: " + folder.RecentMessages);
Console.WriteLine("The number of new unseen messages messages: " + folder.NewUnseenMessages);
// ...
// Disconnect.
client.Disconnect();
Imports ComponentPro
Imports ComponentPro.Net.Mail
...
' Create a new instance of the Imap class.
Dim client As New Imap()
' 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")
' ...
' Obtain information about the 'INBOX' mailbox.
Dim folder As Folder = Await client.GetFolderInfoAsync("INBOX")
' ...
Console.WriteLine("The number of recent messages: " & folder.RecentMessages)
Console.WriteLine("The number of new unseen messages messages: " & folder.NewUnseenMessages)
' ...
' Disconnect.
client.Disconnect()
Get information of an existing mailboxes asynchronously (Event-based asynchronous approach)
using System;
using System.ComponentModel;
using ComponentPro;
using ComponentPro.Net.Mail;
...
public void DoGetMailboxAsync()
{
// Create a new instance of the Imap class.
Imap client = new Imap();
// 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");
// ...
// Register an event handler.
client.GetFolderInfoCompleted += client_GetMailboxInfoCompleted;
// Obtain information about the 'INBOX' mailbox.
client.GetFolderInfoAsync("INBOX");
// ...
// Disconnect.
client.Disconnect();
}
void client_GetMailboxInfoCompleted(object sender, ExtendedAsyncCompletedEventArgs<Folder> e)
{
if (e.Error != null)
{
Console.WriteLine("Error: " + e.Error.ToString());
}
else
{
Console.WriteLine("The number of recent messages: " + e.Result.RecentMessages);
Console.WriteLine("The number of new unseen messages messages: " + e.Result.NewUnseenMessages);
}
}
Imports System.ComponentModel
Imports ComponentPro
Imports ComponentPro.Net.Mail
...
Public Sub DoGetMailboxAsync()
' Create a new instance of the Imap class.
Dim client As New Imap()
' 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")
' ...
' Register an event handler.
AddHandler client.GetFolderInfoCompleted, AddressOf client_GetMailboxInfoCompleted
' Obtain information about the 'INBOX' mailbox.
client.GetFolderInfoAsync("INBOX")
' ...
' Disconnect.
client.Disconnect()
End Sub
Private Sub client_GetMailboxInfoCompleted(ByVal sender As Object, ByVal e As ExtendedAsyncCompletedEventArgs(Of Folder))
If e.Error IsNot Nothing Then
Console.WriteLine("Error: " & e.Error.ToString())
Else
Console.WriteLine("The number of recent messages: " & e.Result.RecentMessages)
Console.WriteLine("The number of new unseen messages messages: " & e.Result.NewUnseenMessages)
End If
End Sub