Skip to content

IMAP Delete

Type: imap-delete  ·  Package: SMTP / IMAP Email Activities v1.0.5

Deletes an email from the IMAP server. By default it moves it to the trash (recoverable); with permanent = true it is removed immediately.

Given the mailId (from IMAP Read), it deletes the email from folder:

  • permanent = false (default): moves it to the folder the server declares as trash. If the server declares no trash folder, the email is deleted permanently and the log warns Email permanently deleted because the server has no Trash folder.
  • permanent = true: flags it as deleted and compacts the folder (expunge) right away. Note that the expunge also removes other emails in that folder that were already flagged as deleted.
ParameterTypeDefaultDescription
hoststring—IMAP server.
usernamestring—Username.
passwordcredential—Password or App Password. Use credential("name")["password"].
mailIdstring—Email UID (from email.Id). Must be numeric.
ParameterTypeDefaultDescription
portint993IMAP port.
folderstring"INBOX"Folder that holds the email.
permanentboolfalsetrue = immediate, permanent deletion; false = to the trash.
securitystring"ssl"Encryption: auto, none, ssl or starttls.

This activity does not return a value.

MessageCause and fix
Invalid 'mailId'. It must be the numeric UID returned by imap-read.mailId is not a number. Pass email.Id from IMAP Read.
'mailId' is required.The parameter is missing or the expression returned null.
Authentication, folder or connection errorSame as in IMAP Read.

Discard advertising emails, to the trash:

For Each items = emails itemVariable = email
└─ activities:
If condition = email.Subject.ToLower().Contains("advertising")
└─ then:
IMAP Delete host = "imap.gmail.com" username = credential("mail-bot")["user"] password = credential("mail-bot")["password"] mailId = email.Id