- 10 May 2022
- 1 Minute to read
Deleting Emails From a Mail Server
- Updated on 10 May 2022
- 1 Minute to read
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.
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.
- From a Designer Project, create a new Flow.
- In the Flow Designer, attach a Get Headers step from the Communication > Email > IMAP category of the Toolbox panel to the Start step.
- On the Properties panel for the Get Headers step, enter "993" for the Port field, "imap.gmail.com" 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.
- From the same category in the Toolbox panel, add a Delete step.
- 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.
- Connect the Delete path to the End step. Click Save to save changes to the Flow.
- Navigate to the Inbox of the specified email account to see the first few unread messages.
- On the Flow Designer, click Debug from the top action bar.
- 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.
- Return to the email account and refresh the Inbox to ensure that the Flow successfully deleted the first unread email.