Sample code for 30+ languages & platforms
C

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

C
#include <C_CkMailMan.h>
#include <C_CkEmail.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMailMan mailman;
    HCkEmail email;

    success = FALSE;

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

    mailman = CkMailMan_Create();

    //  Configure the POP3 server connection.
    CkMailMan_putMailHost(mailman,"pop.example.com");
    CkMailMan_putMailPort(mailman,995);
    CkMailMan_putPopSsl(mailman,TRUE);
    CkMailMan_putPopUsername(mailman,"user@example.com");
    CkMailMan_putPopPassword(mailman,"myPassword");

    //  Fetch a message (headers are enough; the X-UIDL header identifies it on the server).
    email = CkEmail_Create();

    success = CkMailMan_FetchOne(mailman,TRUE,0,1,email);
    if (success == FALSE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        CkMailMan_Dispose(mailman);
        CkEmail_Dispose(email);
        return;
    }

    //  Delete that message using its X-UIDL header.
    success = CkMailMan_DeleteEmail(mailman,email);
    if (success == FALSE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        CkMailMan_Dispose(mailman);
        CkEmail_Dispose(email);
        return;
    }

    //  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.
    success = CkMailMan_Pop3EndSession(mailman);
    if (success == FALSE) {
        printf("%s\n",CkMailMan_lastErrorText(mailman));
        CkMailMan_Dispose(mailman);
        CkEmail_Dispose(email);
        return;
    }

    printf("Deleted the email from the POP3 server.\n");

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


    CkMailMan_Dispose(mailman);
    CkEmail_Dispose(email);

    }