1

I just started using the open-source library called IMAPX to interact with my IMAP mailbox. I am following this article on CodeProject. I can login properly and retrieve the email folders. But the problem is, the article seems to be incomplete which is leaving me in the middle of the road. Firstly the Retrieving Email Folder's part didn't work. I had to do a workaround.Now, I am trying to download the emails of a folder.The article, regarding this issue, has only a few line of code:

private void foldersList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
   var item = foldersList.SelectedItem as EmailFolder;

   if(item != null)
   {
      // Load the folder for its messages.
      loadFolder(item.Title);
   }
}

private void loadFolder(string name)
{
   ContentFrame.Content = new FolderMessagesPage(name);
}

The article doesn't explain anything about FolderMessagesPage . So, I made a test page named FolderMessagesPage. I literally have no idea what to put in that page. Can anybody please guide me?

1 Answers1

0

Unfortunately now I'm having some problems in accessing the article on Code Project, but if you need to retrieve the emails, you can start with the following sample code which retrieves the emails from the Inbox folder. I think that might work for you as well.

        private static readonly ImapClient _client = new ImapX.ImapClient(ServerImapName, ImapPort, ImapProtocol, false);

        if (!_client.Connect())
        {
            throw new Exception("Error on conncting to the Email server.");
        }

        if (!_client.Login(User, Password))
        {
            throw new Exception("Impossible to login to the Email server.");
        }

        public static List<string> GetInboxEmails()
    {
        var lstInEmails = new List<string>();
        // select the inbox folder
        Folder inbox = _client.Folders.Inbox;
        if (inbox.Exists > 0)
        {
            var arrMsg = inbox.Search("ALL", ImapX.Enums.MessageFetchMode.Full);

            foreach (var msg in arrMsg)
            {
                var subject = msg.Subject;
                var mailBody = msg.Body.HasHtml ? msg.Body.Html : msg.Body.Text;
                lstInEmails.Add(string.Concat(subject, " - ", mailBody );
            }
        }


        return lstInEmails;
    }

Hope it helps. Good bytes.

Aleph0
  • 11
  • 1
  • 2