Menu Close
    Searching for an experienced eCommerce & Marketplace Development Company ?

    Use Zend_Mail_Protocol_Imap in Magento 2

    Hello Friends!

    In this blog, we will learn how we can connect with the IMAP protocol using Zend_Mail_Protocol_Imap in Magento 2.

    What is IMAP?

    Internet Message Access Protocol (IMAP) is a communication standard to access email stored on the server. It is a protocol that deals with managing and retrieving email messages from the server.

    To connect with the server, please refer to the below code statements:

    $host = ''; //set your IMAP host
    $imap = new \Zend_Mail_Protocol_Imap($host, 993, true);

    To authenticate the login, please refer to the below code statments:

    $username = '[email protected]'; //set your username of server login
    $password = '[email protected]**'; //set your username of server login
    $status = $imap->login($username, $password); //logged in to server

    Use the below methods to get folder/directory and email information:

    1. $imap->select(); OR $imap->select(‘FOLDER_NAME’); //select the folder(s) and returns array with returned information * otherwise (flags, exists, recent, uidvalidity)

    2. $imap->requestAndResponse(‘SEARCH UNSEEN’, $imap->escapeString(‘*’)) //get all unread email ids

    3. $imap->requestAndResponse(‘SEARCH UNSEEN FROM “[email protected]”‘, $imap->escapeString(‘*’)) //get all unread email id’s from [email protected]

    4. $imap->requestAndResponse(‘SEARCH UNSEEN SUBJECT “test” FROM “[email protected]”‘, $imap->escapeString(‘*’)) //get all unread email id’s from [email protected] with the subject of test

    Thanks 🙂

    Previous Blog: Add validation in system configuration fields before saving the information

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*

    Be the first to comment.

    Back to Top