DeleteMessage Method  

Marks a message for deletion from the current mailbox.


object.DeleteMessage( MessageNumber )


Number of message to delete from the server. This value must be greater than zero. The first message in the mailbox is message number one.

Return Value

A value of zero is returned if the method succeeds. Otherwise, a non-zero error code is returned which indicates the cause of the failure.


The DeleteMessage method only flags the message for deletion. The message is not actually deleted until the mailbox is expunged or another mailbox is selected. This function will return an error if the current mailbox is in read-only mode, such as if it was selected using the ExamineMailbox method.

It is important to note that unlike the POP3 protocol, a message that is marked for deletion is still accessible on the IMAP server until the mailbox is expunged. This means, for example, that a deleted message can still be retrieved using the GetMessage method.

To determine if a message has been marked for deletion, set the Message property to the message number and then check the value of the MessageFlags property to determine if the imapFlagDeleted bit flag has been set.

To remove the deletion flag from the message, use the UndeleteMessage method. To prevent all messages in the current mailbox from being expunged, use the ReselectMailbox function to reset the current mailbox state. Calling the Reset method will also unselect the current mailbox without expunging deleted messages.

See Also

MessageFlags Property, CopyMessage Method, CreateMessage Method, ExamineMailbox Method, ReselectMailbox Method, Reset Method, UndeleteMessage Method