Create, delete, and rename mailboxes with IMAP

The Mail feature, a huge feature set. The first part was released with 4D v17 R4, and since then we have delivered more and more functionalities.

4D v19 is no exception, as it brings new functions to help you manage your mailboxes by programming. That includes creating, renaming, and deleting mailboxes. A mailbox is displayed as a folder in email clients such as Microsoft Outlook or Apple Mail.

HDI Mailboxes management 

Create a mailbox

To create a new mailbox, use the createBox() function. For example, if you want to create a new “Invoices” mailbox at the root:


And if you want to add some children mailboxes to your mailbox, enter the full path with the IMAP server’s separator character:

// create mailboxes name with separator() function
$name1:="Invoices"+$transporter.getDelimiter()+"Atlas Corp"
$name2:="Invoices"+$transporter.getDelimiter()+"Nova Orion Industries"
// Adds new mailboxes related to "Invoices"

Here is what you obtain in your mail browser:

rename a mailbox

If you want to rename your “Invoices” mailbox in “Bills”, use the renameBox() method:

$status:=$transporter.renameBox("Invoices"; "Bills")

Here is what you obtain in the mail browser:


delete a mailbox

If a mailbox is no longer used, you can delete it with the deleteBox() function:

$name3:="Bills"+$transporter.getDelimiter()+"Nova Orion Industries"

Here is what you otbain in your mail browser:



Subscribe to a mailbox

With the subscribe() and unsubscribe() functions, you can define which mailboxes should be displayed as favorites by IMAP clients.

$name4:="Bills"+$transporter.getDelimiter()+"Atlas Corp"

Check out the documentation and the HDI above to learn more about the new functions!

Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.