This project is read-only.

Fetching email that caused newmessagerecieved event to fire

Sep 7, 2013 at 11:19 PM
Edited Sep 7, 2013 at 11:30 PM
I'm new using this component so bear with me. In short, I am trying to capture the email that caused the newmessagerecieved event to fire. Here is my code, is there anything obviously wrong that would cause this to fail? It seems to me, through debugging, that it is failing when it sets tempinbox to INBOX. Why is this?
Imports System.ComponentModel
Imports ActiveUp.Net.Mail

Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

    Private Sub Application_Start()
        Dim worker = New BackgroundWorker()
        AddHandler worker.DoWork, AddressOf StartIdleProcess

        If worker.IsBusy Then
        End If

    End Sub

    Dim _imap As Imap4Client
    Private Sub StartIdleProcess(sender As Object, e As DoWorkEventArgs)
        If _imap IsNot Nothing AndAlso _imap.IsConnected Then
        End If

        _imap = New Imap4Client()
        _imap.ConnectSsl("", 993)
        _imap.Login("", "pass")

        Dim inbox = _imap.SelectMailbox("INBOX")

        AddHandler _imap.NewMessageReceived, AddressOf NewMessageReceived


    End Sub

Private Sub NewMessageReceived(source As Object, e As NewMessageReceivedEventArgs)
        Dim _tempimap As Imap4Client = source
        Dim tempinbox = _tempimap.SelectMailbox("INBOX")
        Dim first As Integer = tempinbox.FirstUnseen
        Dim email As Message = tempinbox.Fetch.MessageObject(first + 1)
    End Sub
End Class