Asynchronously Authenticates the specified user to the IMAP server using GSSAPI.
public ExtendedAsyncResult AuthenticateAsync(
SspiAuthenticationMethod method,
string targetName,
string userName,
string password,
string domain
)
Public Function AuthenticateAsync( _
ByVal method As SspiAuthenticationMethod, _
ByVal targetName As String, _
ByVal userName As String, _
ByVal password As String, _
ByVal domain As String _
) As ExtendedAsyncResult
public:
ExtendedAsyncResult AuthenticateAsync(
SspiAuthenticationMethod method,
String^ targetName,
String^ userName,
String^ password,
String^ domain
);
Parameters
- method
- Requested SSPI mechanism ('NTLM', 'Kerberos' or 'Negotiate').
- targetName
- The target name. If it is set to null ('Nothing' in VB.NET), server hostname will be used instead.
- userName
- The user name. If it is set to null ('Nothing' in VB.NET), integrated authentication (single sign-on) will be used.
- password
- User's password. Can be set to null ('Nothing' in VB.NET) if integrated authentication (single sign-on) is to be used.
- domain
- User's domain. If it is set to null ('Nothing' in VB.NET), it will be determined from the user name. If not available, the default domain will be used.
Return Value
An object that references the asynchronous operation.
Asynchronously connect to an IMAP server and list existing mailboxes (Task-based asynchronous approach).
using System;
using System.ComponentModel;
using System.Text;
using ComponentPro.Net.Mail;
using ComponentPro;
...
// Create a new instance.
Imap client = new Imap();
try
{
// Connect to the IMAP server asynchronously.
await client.ConnectAsync("myserver");
// Or you can specify the IMAP port with
// await client.ConnectAsync("myserver", 143);
// Authenticate the user asynchronously.
await client.AuthenticateAsync("userName", "password");
// Do something here...
StringBuilder sb = new StringBuilder();
FolderCollection list = client.ListFolders();
for (int i = 0; i < list.Count; i++)
{
sb.AppendFormat("{0} - {1}\r\n", i + 1, list[i].Name);
}
Console.WriteLine(sb.ToString());
// ...
// Disconnect asynchronously.
await client.DisconnectAsync();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.ToString());
}
Imports System.ComponentModel
Imports System.Text
Imports ComponentPro.Net.Mail
Imports ComponentPro
...
' Create a new instance.
Dim client As New Imap()
Try
' Connect to the IMAP server asynchronously.
Await client.ConnectAsync("myserver")
' Or you can specify the IMAP port with
' Await client.ConnectAsync("myserver", 143);
' Authenticate the user asynchronously.
Await client.AuthenticateAsync("userName", "password")
' Do something here...
Dim sb As New StringBuilder()
Dim list As FolderCollection = client.ListFolders()
For i As Integer = 0 To list.Count - 1
sb.AppendFormat("{0} - {1}" & vbCrLf, i + 1, list(i).Name)
Next i
Console.WriteLine(sb.ToString())
' ...
' Disconnect asynchronously.
Await client.DisconnectAsync()
Catch ex As Exception
Console.WriteLine("Error: " & ex.ToString())
End Try
Asynchronously connect to an IMAP server and list existing mailboxes (Event-based asynchronous approach).
using System;
using System.ComponentModel;
using System.Text;
using ComponentPro.Net.Mail;
using ComponentPro;
...
public void DoAsyncConnect()
{
// Create a new instance.
Imap client = new Imap();
client.ConnectCompleted += client_ConnectCompleted;
client.AuthenticateCompleted += client_AuthenticateCompleted;
client.DisconnectCompleted += client_DisconnectCompleted;
// Connect to the IMAP server asynchronously.
client.ConnectAsync("myserver");
// Or you can specify the IMAP port with
// client.ConnectAsync("myserver", 143);
// Your code here
// ...
}
void client_ConnectCompleted(object sender, ExtendedAsyncCompletedEventArgs<string> e)
{
Imap client = (Imap)sender;
if (e.Error != null)
{
Console.WriteLine("Error: " + e.Error.ToString());
return;
}
// Authenticate the user asynchronously.
client.AuthenticateAsync("userName", "password");
}
void client_AuthenticateCompleted(object sender, AsyncCompletedEventArgs e)
{
Imap client = (Imap)sender;
if (e.Error != null)
{
Console.WriteLine("Error: " + e.Error.ToString());
return;
}
// Do something here...
StringBuilder sb = new StringBuilder();
FolderCollection list = client.ListFolders();
for (int i = 0; i < list.Count; i++)
{
sb.AppendFormat("{0} - {1}\r\n", i + 1, list[i].Name);
}
Console.WriteLine(sb.ToString());
// ...
// Disconnect asynchronously.
client.DisconnectAsync();
}
void client_DisconnectCompleted(object sender, ExtendedAsyncCompletedEventArgs<string> e)
{
Imap client = (Imap)sender;
if (e.Error != null)
{
Console.WriteLine("Error: " + e.Error.ToString());
}
}
Imports System.ComponentModel
Imports System.Text
Imports ComponentPro.Net.Mail
Imports ComponentPro
...
Public Sub DoAsyncConnect()
' Create a new instance.
Dim client As New Imap()
AddHandler client.ConnectCompleted, AddressOf client_ConnectCompleted
AddHandler client.AuthenticateCompleted, AddressOf client_AuthenticateCompleted
AddHandler client.DisconnectCompleted, AddressOf client_DisconnectCompleted
' Connect to the IMAP server asynchronously.
client.ConnectAsync("myserver")
' Or you can specify the IMAP port with
' client.ConnectAsync("myserver", 143);
' Your code here
' ...
End Sub
Private Sub client_ConnectCompleted(ByVal sender As Object, ByVal e As ExtendedAsyncCompletedEventArgs(Of String))
Dim client As Imap = CType(sender, Imap)
If e.Error IsNot Nothing Then
Console.WriteLine("Error: " & e.Error.ToString())
Return
End If
' Authenticate the user asynchronously.
client.AuthenticateAsync("userName", "password")
End Sub
Private Sub client_AuthenticateCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
Dim client As Imap = CType(sender, Imap)
If e.Error IsNot Nothing Then
Console.WriteLine("Error: " & e.Error.ToString())
Return
End If
' Do something here...
Dim sb As New StringBuilder()
Dim list As FolderCollection = client.ListFolders()
For i As Integer = 0 To list.Count - 1
sb.AppendFormat("{0} - {1}" & vbCrLf, i + 1, list(i).Name)
Next i
Console.WriteLine(sb.ToString())
' ...
' Disconnect asynchronously.
client.DisconnectAsync()
End Sub
Private Sub client_DisconnectCompleted(ByVal sender As Object, ByVal e As ExtendedAsyncCompletedEventArgs(Of String))
Dim client As Imap = CType(sender, Imap)
If e.Error IsNot Nothing Then
Console.WriteLine("Error: " & e.Error.ToString())
End If
End Sub