Deleting Emails From a Mail Server
  • 10 May 2022
  • 1 Minute to read
  • Dark

Deleting Emails From a Mail Server

  • Dark


A Flow can be configured to delete all emails sent by one sender, the first or last email in an account, a set count of emails, unread emails, or even all emails from an account for either an IMAP or POP mail server. The Delete step uses the Unique Id for an email as input, then sends the command to a mail server for the messages that meet the criteria to be deleted.

Using Gmail with Email steps
With Google depreciating Less Secure App settings for Google accounts, users will need to create App Passwords in order to utilize Email steps with Gmail.


The following example will be configured to delete the first unread email from an account using the Delete step found under Communication > Email > IMAP. The example will also work with POP steps.

  1. From a Designer Project, create a new Flow
  2. In the Flow Designer, attach a Get Headers step from the Communication > Email > IMAP category of the Toolbox panel to the Start step. 

  3. On the Properties panel for the Get Headers step, enter "993" for the Port field, "" for the Server field, "1" for Count, and the Username and Password. Check Unread Messages Only and Secure Connection boxes to match the server credentials for the mail server. 

  4. From the same category in the Toolbox panel, add a Delete step. 
  5. On the Delete step's Properties panel, enter the same server credentials used for the Get Headers step. Map the Headers.All UniqueId.First to the Unique Id field.
    The Unique Id is used to identify the Email for the Delete step to delete. Mapping the Get Headers Output to the Delete Step's Unique Id Input allows the step to delete the retrieved message. 

  6. Connect the Delete path to the End step. Click Save to save changes to the Flow.


  1. Navigate to the Inbox of the specified email account to see the first few unread messages.

  2. On the Flow Designer, click Debug from the top action bar.
  3. Click START DEBUGGING. Because the Flow interacts with external systems, the steps can take time to execute. The lag-time seen while debugging is perfectly normal.
  4. Return to the email account and refresh the Inbox to ensure that the Flow successfully deleted the first unread email.

For further information on Flows, visit the Decisions Forum.

Was this article helpful?