Emails are the most commonly used communication in today's digital age. Emails can also be a communication path with IoT devices. Emails can be used to pass commands to IoT devices. Devices can then be programmed and configured to read incoming emails and act accordingly. There may be interesting applications built this way. To receive emails, IoT devices need to be configured as an Email Client. They can retrieve emails only through a standard email protocol. The Internet Message Access Protocol (IMAP) is one of the standard email messaging protocols.
It is a standard email messaging protocol used worldwide in the 21st century. After the Internet era began to gain momentum, most email and messaging tasks were based on POP (Post Office Protocol). As the need arose for a more robust, flexible, and advanced messaging protocol, Mark Crispin invented a remote mailbox protocol in 1986 known as IMAP. It was also known as Interactive Mail Access Protocol and Interim Mail Access Protocol. IMAP was designed with the aim of completely managing the email inbox of various email clients. Clients generally leave a message on the server until the user explicitly deletes it.
Advantage of IMAP over the previous version POP –
IMAP offers several advantages over previous POP versions as follows –
1) Fast response – IMAP version 4 remains connected to the server, unlike POP, where connection is lost briefly after the email download is complete. IMAPv4 allows for faster and faster response because it remains connected to the server.
2) Multiple clients simultaneously connected to same mailbox – IMAP allows multiple clients to connect to same mailbox from different POP where currently connected clients need to be the only client connected mailbox . IMAP allows us to open Gmail on PC, phone or tab at the same time.
3) Message state information – There are different flags in IMAP for different state of email data. For example, the status of the email can be checked whether it has been received, read or responded to. These flags are stored on server end, so opening the mailbox on any device is able to update the flag and the status can be seen on any device.
4) Server-side search – IMAP provides server -side search , so client does not need to download all data to their device for search. This helps to decrease the data payload and speed up email database usage.
However, there are many advantages of IMAP, the disadvantage is that it adds complexity to the implementation relative to POP.
How the IMAP protocol works –
An IMAP server will normally listen for requests on port number 143 and if SSL (Secure Socket Layer) is present then port number 993. Transmission and reception of emails is done using two protocols: SMTP (Simple mail transfer protocol) and IMAP. Emails are received using IMAP protocol in the following steps –
1. Open connection
2. Authentication
3. Select the folder
4. Search
5. Leave
A basic algorithm for receiving emails in IMAP is summarized in the image below –

Fig. 1: Image showing protocol email recovery algorithm
1. Open connection – To initialize the mail retrieval process, you must first open a socket object. A socket is an internal endpoint for sending and receiving data on a single node in a computer network. Data can be sent or received using this socket object.
2. Authentication: Once a socket is established, the username and password must be transmitted for authentication. The server will respond OK to correct credentials and query whether the credentials are incorrect.
3. Select the folder: After the credentials are authorized, the complete mailbox access and folder list can be accessed by sending folder commands. The server will respond with a list of folders such as “Inbox”, “Sent”, “Trash”, “Drafts” etc. server a folder must be selected for which the user wants to view/manage data.
4. Search: Once the folder is selected, data can be received using search commands. The user will receive the list of Unread emails and email data from the selected folder . It has the ability to edit data, mark it as read/unread or delete it if necessary.
5. Logout: When the user logs out of the server, the server closes the connection, therefore the socket object is closed. No data/signals can be transmitted or received using IMAP after the connection is closed.
By implementing the IMAP protocol, STARTTLS can be used to provide secure communication between multiple sender/receiver nodes.
Forms –
All email servers like Gmail and Yahoo support IMAP protocols for email management. A user can read and manage their emails from multiple devices using IMAP. A real-world example is wearable devices. Emails are stored on Google, Google servers and IMAP help in retrieving and managing email data on wearables. Wearable devices have a built-in application that supports IMAP. When connected to the internet, the application initializes a socket object and requests a username and password. The credentials are sent to the server and after verification the user generally sees the data in the Inbox folder. The inbox folder is selected in the app by default and later the app UI also allows you to see other folders. Allows you to manage mailbox like user can delete emails mark them as read /unread etc.
In the next tutorial, learn how to receive commands via Email on a Raspberry Pi-Based IoT Device.