Occurs when the connection with the server gets closed.
Namespace: MailBee.ImapMailAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax Remarks This event is raised in all the cases when the connection gets closed, including
normal shutdown and failures.
Note |
---|
If Abort method is called, the connection is immediately
closed, but no events (including Disconnected) are raised any longer. |
Examples This sample demonstrates that
Disconnected event raises even
on failures (when
MailBeeException is thrown). The sample set very small timeout value
(500 milliseconds), then attempts to connect to the IMAP4 server, log in the account, select Inbox folder, and
download the first message. If the server or network connection is slow, the network operation will time out.
Otherwise, it will succeed. But in both cases,
Disconnected will still be raised.
using System;
using MailBee;
using MailBee.ImapMail;
using MailBee.Mime;
class Sample
{
private static void OnDisconnected(object sender, DisconnectedEventArgs e)
{
if (e.IsNormalShutdown)
{
Console.WriteLine("Normally disconnected from the server.");
}
else
{
Console.WriteLine("The connection was terminated.");
}
}
static void Main(string[] args)
{
Imap imp = new Imap();
imp.Timeout = 500;
imp.Disconnected += new DisconnectedEventHandler(OnDisconnected);
imp.Connect("mail.host.com");
imp.Login("jdoe@host.com", "secret");
imp.SelectFolder("INBOX");
MailMessage msg = imp.DownloadEntireMessage(1, false);
imp.Disconnect();
}
}
Imports System
Imports MailBee
Imports MailBee.ImapMail
Imports MailBee.Mime
Module Sample
Private Sub OnDisconnected(ByVal sender As Object, ByVal e As DisconnectedEventArgs)
If (e.IsNormalShutdown) Then
Console.WriteLine("Normally disconnected from the server.")
Else
Console.WriteLine("The connection was terminated.")
End If
End Sub
Sub Main(ByVal args As String())
Dim imp As New Imap
imp.Timeout = 500
AddHandler imp.Disconnected, AddressOf OnDisconnected
imp.Connect("mail.host.com")
imp.Login("jdoe@host.com", "secret")
imp.SelectFolder("INBOX")
Dim msg As MailMessage = imp.DownloadEntireMessage(1, False)
imp.Disconnect()
End Sub
End Module
See Also