Sample code for 30+ languages & platforms
Unicode C

Send a Raw SMTP Command

See more SMTP Examples

Demonstrates the Chilkat MailMan.SmtpSendRawCommand method, which sends a raw command to the SMTP server and returns the server's response. The second argument specifies the charset to use if the command contains non-US-ASCII characters, and the third indicates whether to base64-encode the command before sending. This example sends a raw NOOP on an open connection.

Background: SMTP is a line-based text protocol (EHLO, MAIL FROM, RCPT TO, DATA, QUIT), so a raw-command hook lets you issue anything Chilkat doesn't wrap — a server extension, or a custom step during a manual auth exchange. The base64 flag exists because some SMTP exchanges (notably AUTH challenge/response) require the argument to be base64-encoded on the wire.

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.SmtpSendRawCommand method, which sends a raw command to the SMTP
    //  server and returns the server's response.  The 2nd argument is the charset used if the
    //  command contains non-US-ASCII characters, and the 3rd indicates whether to base64-encode
    //  the command before sending.

    mailman = CkMailManW_Create();

    //  Configure the SMTP server connection.
    CkMailManW_putSmtpHost(mailman,L"smtp.example.com");
    CkMailManW_putSmtpPort(mailman,465);
    CkMailManW_putSmtpSsl(mailman,TRUE);
    CkMailManW_putSmtpUsername(mailman,L"user@example.com");
    CkMailManW_putSmtpPassword(mailman,L"myPassword");

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

    //  Send the raw SMTP NOOP command (not base64-encoded).
    response = CkMailManW_smtpSendRawCommand(mailman,L"NOOP",L"us-ascii",FALSE);
    if (CkMailManW_getLastMethodSuccess(mailman) == FALSE) {
        wprintf(L"%s\n",CkMailManW_lastErrorText(mailman));
        CkMailManW_Dispose(mailman);
        return;
    }

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

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



    CkMailManW_Dispose(mailman);

    }