Sample code for 30+ languages & platforms
PowerBuilder

Delete a POP3 Message by UIDL

See more POP3 Examples

Demonstrates the Chilkat MailMan.DeleteByUidl method, which marks the POP3 message identified by a UIDL for deletion. UIDLs are preferred over message numbers because they remain stable across sessions while the message stays in the mailbox. This example marks a message for deletion by its UIDL.

Background: Because a UIDL uniquely and persistently identifies a message, deleting by UIDL is the reliable way to remove exactly the message you intend — even if the mailbox changed since you last looked. As with all POP3 deletion, the message is only marked during the session and is actually removed when the session ends normally (the QUIT command).

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman

li_Success = 0

//  Demonstrates the MailMan.DeleteByUidl method, which marks the POP3 message identified by
//  a UIDL for deletion.  UIDLs are preferred over message numbers because they remain stable
//  across sessions while the message remains in the mailbox.

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

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

//  Mark a specific message for deletion by its UIDL.

li_Success = loo_Mailman.DeleteByUidl("0000000123abcdef")
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if

//  Unless the ImmediateDelete property is set to 1, the message is only marked for
//  deletion.  End the POP3 session (which sends the QUIT command) to commit the deletion
//  on the server.
li_Success = loo_Mailman.Pop3EndSession()
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if

Write-Debug "Deleted the message 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.


destroy loo_Mailman