MailBee.NET Objects 6.0

Imap.DeleteMessages Method 

Marks the specified messages in the currently selected folder as deleted.

public bool DeleteMessages(
   string messageIndexSet,
   bool indexIsUid
);

Parameters

messageIndexSet
A message sequence string containing ordinal message numbers or UIDs. Can be composed manually or using ToString.
indexIsUid
If true, messageIndexSet is treated as a sequence of UIDs; otherwise, as a sequence of ordinal message numbers.

Return Value

true if the messages have been marked as deleted successfully; otherwise, false.

Remarks

To learn how to specify a valid message sequence (messageIndexSet value), see DownloadEnvelopes topic.

Note    This method just sets "\Deleted" flag for the specified messages. To purge deleted messages permanently, call Expunge method or explicitly unselect the folder using Close method.

To learn now to undelete messages marked as deleted, see the sample in SetMessageFlags topic.

Exceptions

Exception TypeCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

This sample marks the first message and the messages #5, #6, and #7 in the inbox as deleted.

[C#]
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server, login and select inbox.
        imp.Connect("mail.server.com");
        imp.Login("jdoe", "secret");
        imp.SelectFolder("INBOX");

        // Mark messages as deleted.
        imp.DeleteMessages("1,5:7", false);

        // Uncomment the next line to purge deleted messages.
        // imp.Close();

        // Disconnect from the server.
        imp.Disconnect();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    Sub Main()
        Dim imp As New Imap

        ' Connect to the server, login and select inbox.
        imp.Connect("mail.server.com")
        imp.Login("jdoe", "secret")
        imp.SelectFolder("INBOX")

        ' Mark messages as deleted.
        imp.DeleteMessages("1,5:7", False)

        ' Uncomment the next line to purge deleted messages.
        ' imp.Close()

        ' Disconnect from the server.
        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace