Capturing Imap related events

Top  Previous  Next

The Imap class may publish one or more events during the lifetime of an Imap session. Any object that subscribes to events published by the Imap class can receive and process these events.

 

The ConnectedEvent is fired by the Imap instance once a connection to the IMAP server has been established.

The DisconnectedEvent is fired by the Imap instance once the connection to the IMAP server has been released.

The CommandSentEvent is fired by the Imap instance for each command sent to the IMAP server.

The DataReceivedEvent is fired by the Imap instance for each response received from the IMAP server.

The MessageRetrievedEvent is fired by the Imap instance for each message retrieved from the IMAP server.

 

 

Capturing the ConnectedEvent event

 

The ConnectedEvent is published by the Imap instance once a connection to the Imap server has been established.

 

Example

 

[C#]

myImap = new Imap(hostname, username, password);

// Subscribe to event

myImap.ConnectedEvent += new Imap.ConnectedEventHandler(OnConnected);

 

// Define Connected Event handler

public void OnConnected(object sender, ImapConnectedEventArgs e) {

 Console.WriteLine("Connected to {0}", e.Host);

}

 

 

[Visual Basic]

Public WithEvents myImap As Imap

myImap = New Imap(hostname, username, password);

 

' Define Connected Event handler

Private Sub OnConnected( ByVal sender As Object, ByVal e As ImapConnectedEventArgs) Handles myImap.ConnectedEvent

 Console.WriteLine("Connected to {0}", e.Host);

End Sub

 

 

Capturing the DisconnectedEvent event

 

The DisconnectedEvent is published by the Imap instance once the connection to the Imap server has been released.

 

Example

 

[C#]

myImap = new Imap(hostname, username, password);

// Subscribe to event

myImap.DisconnectedEvent += new Imap.DisconnectedEventHandler(OnDisconnected);

 

// Define Disconnected Event handler

public void OnDisconnected(object sender, ImapDisconnectedEventArgs e) {

 Console.WriteLine("Disconnected");

}

 

 

[Visual Basic]

Public WithEvents myImap As Imap

myImap = New Imap(hostname, username, password);

 

' Define Disconnected Event handler

Private Sub OnDisconnected( ByVal sender As Object, ByVal e As ImapDisconnectedEventArgs) Handles myImap.DisconnectedEvent

 Console.WriteLine("Disconnected");

End Sub

 

 

Capturing the CommandSentEvent event

 

The CommandSentEvent is published by the Imap instance for each command sent to the Imap server.

 

Example

 

[C#]

myImap = new Imap(hostname, username, password);

// Subscribe to event

myImap.CommandSentEvent += new Imap.CommandSentEventHandler(OnCommandSent);

 

// Define CommandSent Event handler

public void OnCommandSent(object sender, ImapCommandSentEventArgs e) {

 Console.WriteLine("Command: " + e.Command);

}

 

 

[Visual Basic]

Public WithEvents myImap As Pop

myImap = New Pop(hostname, username, password);

 

' Define CommandSent Event handler

Private Sub OnCommandSent( ByVal sender As Object, ByVal e As ImapCommandSentEventArgs) Handles myImap.CommandSentEvent

 Console.WriteLine("Command: " & e.Command);

End Sub

 

 

Capturing the DataReceivedEvent event

 

The DataReceivedEvent is published by the Imap instance for each response received from the Imap server.

 

Example

 

[C#]

myImap = new Imap(hostname, username, password);

// Subscribe to event

myImap.DataReceivedEvent += new Imap.DataReceivedEventHandler(OnDataReceived);

 

// Define DataReceived Event handler

public void OnDataReceived(object sender, ImapDataReceivedEventArgs e) {

 Console.WriteLine("Response: " + e.Response);

}

 

 

[Visual Basic]

Public WithEvents myImap As Imap

myImap = New Imap(hostname, username, password);

 

' Define DataReceived Event handler

Private Sub OnDataReceived( ByVal sender As Object, ByVal e As ImapDataReceivedEventArgs) Handles myImap.DataReceivedEvent

 Console.WriteLine("Response: " & e.Response);

End Sub

 

 

Capturing the MessageRetrievedEvent event

 

The MessageRetrievedEvent is published by the Imap instance for each message retrieved from the Imap server.

 

Example

 

[C#]

myImap = new Imap(hostname, username, password);

// Subscribe to event

myImap.MessageRetrievedEvent += new Imap.MessageRetrievedEventHandler(OnMessageRetrieved);

 

// Define MessageRetrieved Event handler

public void OnMessageRetrieved(object sender, ImapMessageRetrievedEventArgs e) {

 Console.WriteLine("Message: " + e.Message.GetSubject());

}

 

 

[Visual Basic]

Public WithEvents myImap As Imap

myImap = New Imap(hostname, username, password);

 

' Define MessageRetrieved Event handler

Private Sub OnMessageRetrieved( ByVal sender As Object, ByVal e As ImapMessageRetrievedEventArgs) Handles myImap.MessageRetrievedEvent

 Console.WriteLine("Message: " & e.Message.GetSubject());

End Sub

 

 

 





Home | Company | Products | Solutions | Purchase | Support | Services | Blog

© 2021 JSCAPE LLC