4D Blog

Home Product Receive email with IMAP protocol

Receive email with IMAP protocol

July 30, 2020

Product

In 4D v18, we introduced a new way to send emails. Then in 4D v18 R2, we added a new way to retrieve emails using POP3. Now in 4D v18 R4, we’re taking the first steps for a new way to handle the IMAP protocol. As we did for SMTP and POP3, there’s a new IMAP New transporter command to handle the IMAP protocol.

The Internet Message Access Protocol (IMAP) is an Internet standard protocol used by email clients to retrieve email messages from a mail server. This protocol makes it possible to manage multiple mailboxes, download emails, perform searches on the server, manage message state, and a lot more!

And with this first IMAP feature, you can add methods to the transporter to: have the list of the available mailboxes, select a mailbox, and receive email from the selected mailbox. Let’s see how.

The HDI below demonstrates how to receive email via IMAP:

HDI receive email via IMAP

create IMAP transporter

Like SMTP and POP3, when using the IMAP protocol, you first need to create a transporter (via the IMAP New transporter command):

$server:=New object
$server.host:="yourIMAPhost.com"
$server.port:=995
$server.user:="4D.IMAP@mail.com"
$server.password:="XXXXXX"
// Create a transporter from your server information
$IMAP_Transporter:=IMAP New transporter($server)

Select mailbox

Because IMAP supports multiple mailboxes, the first thing to do is specify the mailbox you want.

You can obtain a list of all the avaliable mailboxes on your mail server with the getBoxList method:

$boxList:=$IMAP_Transporter.getBoxList()
Alert("Your first mailbox name is "+$boxList[0].name)

Once you know the name of the specific mailbox you need, simply use the selectBox method:

$boxInfo:=$transporter.selectBox($boxList[$boxId].name)

This command returns useful information such as:

  • the number of emails in the mailbox
  • the number of recent messages

Download email

You have two ways to identify the mail you want to download:

  • The first is to use the position of the email in the mailbox, just like you would for POP3. For example, if you want to download the last received mail:

$mail:=$transporter.getMail($boxInfo.mailCount)

  • The second is to use the id attribute of the email object returned by the IMAP server. This way is best to use when you want to retrieve a specific email since an email’s position in the mailbox can be modified when you delete emails:

$mail:=$transporter.getMail($emailId)

As we said earlier, this is the first feature for IMAP. There’s more coming. Stay tuned!

Discuss

Tags IMAP, Mail, v18 R4, v19

Latest related posts

  • October 23, 2025

    Starting Qodly studio is just two clicks away

  • October 22, 2025

    Localize your Qodly Pages: A Practical Guide

  • October 21, 2025

    New Way to Control Your HTTP Responses

Fabrice Mainguené
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.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • AI
  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D AIKit 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R10 21 Administration AI Artificial Intelligence Build application CI/CD Class Client/Server Code editor Collections Formula Listbox Logs Mail Microsoft 365 Network Objects OpenAI ORDA PDF Pictures Preemptive Programming REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy