Working example of IMAP client

Hi everyone,

I am working with the MBS plug-ins to try to get a (fairly simple) application running. I want to download, for my various IMAP accounts, a folder tree structure. I have hundreds of mail folders and Mail is not a very effective application for finding folders.

Anyway, I decided to buy the MBS plug-in as it seems to go some way towards what I want. The CURL IMAP example does indeed download something from my IMAP mail account, but it looks like just a set of numeric IDs. Each of them appears to be for a single email message. This approach seems to require a fair amount of low-level knowledge of CURL, so I’m having some difficulty navigating it… unfortunately the CURL Email client example falls over with CURL Error code: 78. I can’t find what that means either.

Does anyone know of any example code that will help me find my way? I looked at the Chilkat plug-ins but I can’t follow those either! I saw reference to a Git project too, but that has no example code that I can see.

To recap, I want to download a list of the names of folders and sub-folders in such a way that I can put them into a tree structure. Nothing else.



The correct function in the Chilkat plugin is ListMailboxes or ListMailboxesAsync.

The code assumes that you have already connected:

[code]CkoMailboxTask = CkoImap.ListMailboxesAsync("", “*”)
call CkoMailboxTask.Run
While CkoMailboxTask.Finished <> True
if globals.StopArchiving then
if not CkoMailboxTask.Cancel then app.SleepCurrentThread(10)
Return Nil
end if

if not CkoMailboxTask.TaskSuccess then
globals.theErrorLog.LogItem(CurrentMethodName + " task didn’t finish")
Return Nil
end if

dim CkoMailboxes as new Chilkat.Mailboxes
if not CkoMailboxes.LoadTaskResult(CkoMailboxTask) then
globals.theErrorLog.LogItem(CurrentMethodName + " wasn’t able to load result from task")
Return Nil
end if

if ckoMailboxes = Nil then
globals.theErrorLog.LogItem "no mailboxes found " + CkoImap.LastErrorText
Return Nil
end if

for currentMailbox as Integer = 0 to ckoMailboxes.Count - 1
if ckoMailboxes.IsSelectable(currentMailbox) then
MailboxesOriginal.AddRow ckoMailboxes.GetName(currentMailbox)
MailboxFlags.AddRow ckoMailboxes.GetFlags(currentMailbox)
end if

'get mailbox divider
MailboxDivider = CkoImap.SeparatorChar[/code]

Theoretically, you could use my IMAP test app. That’s for users who have trouble connecting. It connects, shows a list of mailboxes and downloads the emails of a selected mailbox.

Which example did you try?
Usually you load the list of messages to get a list of IDs and then query each email by it’s unique ID.

Just thought I’d add that if this is connecting to Google’s imap then we have been informed that very soon they will totally block user/password authentication and require oauth2.

No, for Gmail you need to get your app approved by Google. I’m still not sure if that will cost money.

I don’t know if it costs money either, I’m just starting to look at the whole process now because our smtp sending has started to fail because it is ‘a less secure app’ according to google.