LiveCode LessonsLiveCode LessonsHow To - Step-By-Step Guides To Tasks In LiveCodeTSNetHow to use tsNet to display the folders stored in an IMAP account

How to use tsNet to display the folders stored in an IMAP account


When working with IMAP accounts, it is often a requirement to get a list of the folders that are stored in a user's mailbox.

This lesson demonstrates how retrieving a folder structure for an IMAP account with tsNet works in a similar manner to the retrieval of directory listings from a FTP server.

Lay out the Stack

Create a new stack then drag a button and a field onto it.

Set the name of this field to "Output".

Save this stack.

Create the Script

Edit the script of the button that you placed on the stack by right clicking on the button and selecting "edit script".

Add the following code.

on mouseUp
   -- This is the IMAP server that you want to connect to, use "imaps://" to specify an SSL connection is to be made
   put "imaps://" into tURL
   -- Add the IMAP server username and password into the tSettings array to be passed to the tsNet calls
   put "username" into tSettings["username"]
   put "password" into tSettings["password"]
   -- In a similar manner to FTP, you can use the tsNetGetSync command to retrieve an IMAP folder listing
   put tsNetGetSync(tURL, tHeaders, tRecvHeaders, tResult, tBytes, tSettings) into tData
   if tResult is 0 then
      put tData into field "Output"
      -- Otherwise an error has occurred, advise the user
      answer "Error connecting to server:" && tResult
   end if
end mouseUp
Click to copy


Switch to Run mode and click the button.

More information

The code in this example shows how the retrieval of folders stored in an IMAP account only requires a single call to tsNetGetSync.  In order to retrieve sub-folders of a particular folder, you only need to append the URL passed to tsNetGetSync with a slash followed by the folder name that you wish to search under.

For example, you would use a URL similar to the one below in order to retrieve the sub-folders stored under a folder named "LiveCode".



Add your comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.