Click here to Skip to main content
15,887,322 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to follow this article

What i am trying to do is retrieve emails using IMAPX.The problem is, when i create a class to handle all the function using this code :

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Text
Imports System.Threading.Tasks
Imports ImapX
Imports ImapX.Collections
Imports System.Windows

Namespace ImapPackage

    Class ImapService

        Private Shared Property client As ImapClient

        Public Shared Sub Initialize()
            client = New ImapClient("imap.gmail.com", True)
            If Not client.Connect() Then
                Throw New Exception("Error connecting to the client.")
            End If
        End Sub

        Public Shared Function Login(ByVal u As String, ByVal p As String) As Boolean
            Return client.Login(u, p)
        End Function

        Public Shared Sub Logout()
            If client.IsAuthenticated Then
                client.Logout()
            End If

            MainWindow.LoggedIn = False
        End Sub

        Public Shared Function GetFolders() As List(Of EmailFolder)
            Dim folders = New List(Of EmailFolder)()
            For Each folder In client.Folders
                folders.Add(New EmailFolder With {.Title = folder.Name})
            Next

            client.Folders.Inbox.StartIdling()
            client.Folders.Inbox.OnNewMessagesArrived += AddressOf Inbox_OnNewMessagesArrived
            Return folders
        End Function

        Private Shared Sub Inbox_OnNewMessagesArrived(ByVal sender As Object, ByVal e As IdleEventArgs)
            MessageBox.Show($"A new message was downloaded in {e.Folder.Name} folder.")
        End Sub

        Public Shared Function GetMessagesForFolder(ByVal name As String) As MessageCollection
            client.Folders(name).Messages.Download()
            Return client.Folders(name).Messages
        End Function
    End Class
End Namespace


The exception i get :

1 • Type EMAILFOLDER is not defined
2 • Public event OnNewMessageArrived as EventHandler(Of IdleEVentArgs) is an event and cannot be called directly.Use a RaiseEvent statement

The 2nd problem is not that serious but how do i fix the 1st one ? What am i missing ?

What I have tried:

Whatever i tried is mentioned in the post above .
Posted
Updated 11-Jan-18 6:35am
Comments

You have already asked in the article forum (Building custom email client in WPF using C#[^]).

Please be a little patient. I think that the author will answer (he is still active her at CP but might not login daily). He also gots a notification mail about your forum post so that he knows about it.

However, the EmailFolder class is defined in HomePage.xaml.cs:
C#
class EmailFolder
{
    public string Title { get; set; }
}
So you have to create a corresponding VB.Net class or just use a String instead.
 
Share this answer
 
For the second problem, your converted code is slightly off. VB.NET uses AddHandler[^] to wire up event handlers, not the += syntax that C# uses.
VB.NET
AddHandler client.Folders.Inbox.OnNewMessagesArrived, AddressOf Inbox_OnNewMessagesArrived
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900