Sample code for 30+ languages & platforms
PowerBuilder Requires Chilkat v11.1.0+

Delete All Email in a POP3 Mailbox

Delete all email in a POP3 mailbox.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_StUidls

li_Success = 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

//  The mailman object is used for receiving (POP3) 
//  and sending (SMTP) email.
loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
    destroy loo_Mailman
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Set the POP3 server's hostname
loo_Mailman.MailHost = "pop.example.com"

//  Set the POP3 login/password.
loo_Mailman.PopUsername = "bob@example.com"
loo_Mailman.PopPassword = "****"

//  Make sure the ImmediateDelete property is set (this is the default)
//  If ImmediateDelete is not set, messages marked for deletion
//  by the Delete* methods will not be deleted until the POP3
//  connection is closed by calling Pop3EndSession.
loo_Mailman.ImmediateDelete = 1

//  First, get all the UIDLs.
loo_StUidls = create oleobject
li_rc = loo_StUidls.ConnectToNewObject("Chilkat.StringTable")

li_Success = loo_Mailman.FetchUidls(loo_StUidls)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_StUidls
    return
end if

//  Next, delete them all.
li_Success = loo_Mailman.DeleteUidlSet(loo_StUidls)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_StUidls
    return
end if

//  We're done with the POP3 session, so it doesn't hurt to call this...
li_Success = loo_Mailman.Pop3EndSession()
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_StUidls
    return
end if

Write-Debug "Success."


destroy loo_Mailman
destroy loo_StUidls