Sample code for 30+ languages & platforms
Xbase++

Delete a Bundle of POP3 Messages

See more POP3 Examples

Demonstrates the Chilkat MailMan.DeleteBundle method, which deletes POP3 messages using the UIDLs stored in the X-UIDL headers of the Email objects in an EmailBundle. An email without an X-UIDL header is skipped. This example fetches all messages and deletes them.

Background: DeleteBundle is the batch version of DeleteEmail: it marks every message in a downloaded bundle for deletion in one call. A typical "download and clear the mailbox" workflow is to fetch all messages, process them, then delete the whole bundle. Because a bundle can be filtered or built selectively, you can also delete just the subset you no longer need. The deletions commit when the POP3 session ends.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oMailman
LOCAL oBundle

nSuccess := 0

//  Demonstrates the MailMan.DeleteBundle method, which deletes POP3 messages using the UIDLs
//  stored in the X-UIDL headers of the Email objects in an EmailBundle.  An email without an
//  X-UIDL header is skipped.

oMailman := CreateObject("Chilkat.MailMan")

//  Configure the POP3 server connection.
oMailman:MailHost := "pop.example.com"
oMailman:MailPort := 995
oMailman:PopSsl := 1
oMailman:PopUsername := "user@example.com"
oMailman:PopPassword := "myPassword"

//  Fetch all messages (headers are enough; each carries an X-UIDL header).
oBundle := CreateObject("Chilkat.EmailBundle")

nSuccess := oMailman:FetchAll(1, 1, 0, oBundle)
IF (nSuccess == 0)
    ? oMailman:LastErrorText
    oMailman:destroy()
    oBundle:destroy()
    RETURN
ENDIF

//  Delete every message in the bundle.
nSuccess := oMailman:DeleteBundle(oBundle)
IF (nSuccess == 0)
    ? oMailman:LastErrorText
    oMailman:destroy()
    oBundle:destroy()
    RETURN
ENDIF

//  Unless the ImmediateDelete property is set to 1, the messages are only marked for
//  deletion.  End the POP3 session (which sends the QUIT command) to commit the deletions.
nSuccess := oMailman:Pop3EndSession()
IF (nSuccess == 0)
    ? oMailman:LastErrorText
    oMailman:destroy()
    oBundle:destroy()
    RETURN
ENDIF

? "Deleted " + Str(oBundle:MessageCount) + " messages from the POP3 server."

//  Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
//  connects and authenticates -- using the property settings above -- whenever a server
//  operation requires it.  Calling the explicit connect/authenticate methods can still be
//  helpful to determine whether a failure occurs while connecting or while authenticating.

oMailman:destroy()
oBundle:destroy()