DeleteMessages Method


Marks one or more messages in the currently selected mailbox as "deleted".

This method does not really deletes messages, it just sets "deleted" flag for them. To permanently remove messages marked as "deleted", call Expunge or ExpungeAndClose method.

To delete a single message, set First and Last parameters to the same message number or UID.

To delete an arbitrary set of messages, specify MessageSet property and pass -1 as First value (Last value is not important when First is -1). AsUID parameter is still honored when IDs are taken from MessageSet property (depending on AsUID value, they will be treated as UIDs or ordinal message numbers).

To delete all messages starting from a particular message number (not UID), set First parameter to this number and Last one to MessageCount value. If working with UIDs, you can specify UID of the fist message as First and -1 as Last value (in case if you don't know the UID of the last message).


blnResult = ObjectName.DeleteMessages(First, Last, AsUID)  
Parameters:  
First As Long Message number or UID of the first message in the deleted range, or -1 to use MessageSet as input.  
Last As Long Message number or UID of the last message in the deleted range. -1 means "last message in the mailbox".  
AsUID As Boolean If True, First and Last parameters are treated as UIDs. Otherwise, they are treated as message numbers.  
Return value As Boolean True if successful, False if error has occurred. You can check ErrDesc property or log file to get more detailed error information.  

Usage example:

' This sample deletes the first message from "Inbox" mailbox

Dim Mailer
'Using visual basic to create object
Set Mailer = CreateObject("MailBee.IMAP4")
'Using ASP to create object
'Set Mailer = Server.CreateObject("MailBee.IMAP4")
'In ASP use Response.Write instead of MsgBox

Mailer.EnableLogging = True ' Logging helps discover any problems
Mailer.LogFilePath = "C:\Temp\imap4_log.txt"

Mailer.LicenseKey = "put your license key here"
If Mailer.Connect("mail.server.com", 143, "MyName", "MyPassword") Then
  If Mailer.SelectMailbox("Inbox") Then
    If Mailer.DeleteMessages(1, 1, False) Then
      MsgBox "Message marked as deleted"
    End If
  End If
  Mailer.Disconnect
Else
  MsgBox Mailer.ErrDesc
End If

See Also:

MessageCount Property

Expunge Method
ExpungeAndClose Method
SelectMailbox Method


Copyright © 2002-2022, AfterLogic Corporation. All rights reserved.