Sample code for 30+ languages & platforms
Unicode C

Send a Raw POP3 Command

See more POP3 Examples

Demonstrates the Chilkat MailMan.Pop3SendRawCommand method, which sends a raw command to the POP3 server and returns the server's response. The second argument specifies the charset to use if the command contains non-US-ASCII characters. This example sends the POP3 STAT command within an open session.

Background: POP3 is a simple line-based text protocol — the client sends short commands like STAT, LIST, UIDL, or RETR and the server replies with +OK or -ERR. This method is an escape hatch for issuing a command Chilkat doesn't wrap directly, or a server-specific extension. Note that the session must already be open, since a raw command assumes an authenticated connection.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkMailManW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMailManW mailman;
    const wchar_t *response;

    success = FALSE;

    //  Demonstrates the MailMan.Pop3SendRawCommand method, which sends a raw command to the POP3
    //  server and returns the server's response.  The second argument is the charset used if the
    //  command contains non-US-ASCII characters.

    mailman = CkMailManW_Create();

    //  Configure the POP3 server connection.
    CkMailManW_putMailHost(mailman,L"pop.example.com");
    CkMailManW_putMailPort(mailman,995);
    CkMailManW_putPopSsl(mailman,TRUE);
    CkMailManW_putPopUsername(mailman,L"user@example.com");
    CkMailManW_putPopPassword(mailman,L"myPassword");

    success = CkMailManW_Pop3BeginSession(mailman);
    if (success == FALSE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkMailManW_Dispose(mailman);
        return;
    }

    //  Send the raw POP3 STAT command, which returns the message count and maildrop size.
    response = CkMailManW_pop3SendRawCommand(mailman,L"STAT",L"us-ascii");
    if (CkMailManW_getLastMethodSuccess(mailman) == FALSE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkMailManW_Dispose(mailman);
        return;
    }

    wprintf(L"STAT response: %s\n",response);

    success = CkMailManW_Pop3EndSession(mailman);
    if (success == FALSE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkMailManW_Dispose(mailman);
        return;
    }



    CkMailManW_Dispose(mailman);

    }