Sample code for 30+ languages & platforms
PowerBuilder

Delete a POP3 Message via an Email Object

See more POP3 Examples

Demonstrates the Chilkat MailMan.DeleteEmail method, which deletes a POP3 message using the UIDL stored in the X-UIDL header of an Email object. The email must contain an X-UIDL header, which it does after being fetched from the server. This example fetches a message and then deletes it.

Background: When Chilkat downloads a POP3 message it records the server UIDL in an X-UIDL header on the Email object. DeleteEmail uses that header to tell the server which message to remove — a natural "process then delete" flow: fetch a message, act on it, then delete it. As always in POP3, the deletion is only committed when the session ends (unless ImmediateDelete is set).

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman
oleobject loo_Email

li_Success = 0

//  Demonstrates the MailMan.DeleteEmail method, which deletes a POP3 message using the UIDL
//  stored in the X-UIDL header of an Email object.  The email must contain an X-UIDL header
//  (as it does after being fetched from the server).

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"

//  Fetch a message (headers are enough; the X-UIDL header identifies it on the server).
loo_Email = create oleobject
li_rc = loo_Email.ConnectToNewObject("Chilkat.Email")

li_Success = loo_Mailman.FetchOne(1,0,1,loo_Email)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Email
    return
end if

//  Delete that message using its X-UIDL header.
li_Success = loo_Mailman.DeleteEmail(loo_Email)
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Email
    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.
li_Success = loo_Mailman.Pop3EndSession()
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    destroy loo_Email
    return
end if

Write-Debug "Deleted the email 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
destroy loo_Email