Deleting a message

The sample deletes first message from the mailbox.

Note: DeleteMessage method just marks a message for deletion. Actual deletion takes place when Disconnect method is called and POP3 session is closed.

Visual Basic

Dim objPOP3

' Create POP3 object
Set objPOP3 = CreateObject("MailBee.POP3")

' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"

' Set POP3 server name
objPOP3.ServerName = "mail.server.com"

' Set user credentials
objPOP3.UserName = "username"
objPOP3.Password = "password"

' Connect to the server and log in the mailbox
If objPOP3.Connect Then

  ' Mark first message for deletion
  If objPOP3.DeleteMessage(1) Then
    MsgBox "Message #1 marked for deletion"
  Else
    ' Display error information
    MsgBox "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc
  End If

  ' Close the connection. The message is
  ' actually deleted here
  If objPOP3.Disconnect Then
    MsgBox "Message #1 purged"
  End If
Else
  ' Display error information
  MsgBox "Error #" & objPOP3.ErrCode
  MsgBox "Server response: " & objPOP3.ServerResponse
End If

ASP

<%
Dim objPOP3

' Create POP3 object
Set objPOP3 = Server.CreateObject("MailBee.POP3")

' Unlock POP3 object
objPOP3.LicenseKey = "put your license key here"

' Set POP3 server name
objPOP3.ServerName = "mail.server.com"

' Set user credentials
objPOP3.UserName = "username"
objPOP3.Password = "password"

' Connect to the server and log in the mailbox
If objPOP3.Connect Then

  ' Mark first message for deletion
  If objPOP3.DeleteMessage(1) Then
    Response.Write "Message #1 marked for deletion <br>"
  Else
    ' Display error information
    Response.Write "Error #" & objPOP3.ErrCode & ", " & objPOP3.ErrDesc
  End If

  ' Close the connection. The message is
  ' actually deleted here
  If objPOP3.Disconnect Then
    Response.Write "Message #1 purged"
  End If
Else
  ' Display error information
  Response.Write "Error #" & objPOP3.ErrCode & "<br>"
  Response.Write "Server response: " & objPOP3.ServerResponse
End If
%>

See Also:
DeleteMessage Method