Sample code for 30+ languages & platforms
DataFlex

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 DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMailman
    Variant vEmail
    Handle hoEmail
    String sTemp1

    Move False To iSuccess

    //  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).

    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    //  Configure the POP3 server connection.
    Set ComMailHost Of hoMailman To "pop.example.com"
    Set ComMailPort Of hoMailman To 995
    Set ComPopSsl Of hoMailman To True
    Set ComPopUsername Of hoMailman To "user@example.com"
    Set ComPopPassword Of hoMailman To "myPassword"

    //  Fetch a message (headers are enough; the X-UIDL header identifies it on the server).
    Get Create (RefClass(cComChilkatEmail)) To hoEmail
    If (Not(IsComObjectCreated(hoEmail))) Begin
        Send CreateComObject of hoEmail
    End

    Get pvComObject of hoEmail to vEmail
    Get ComFetchOne Of hoMailman True 0 1 vEmail To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Delete that message using its X-UIDL header.
    Get pvComObject of hoEmail to vEmail
    Get ComDeleteEmail Of hoMailman vEmail To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Unless the ImmediateDelete property is set to True, the message is only marked for
    //  deletion.  End the POP3 session (which sends the QUIT command) to commit the deletion.
    Get ComPop3EndSession Of hoMailman To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "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.


End_Procedure