Sample code for 30+ languages & platforms
Unicode C

Explicitly Connect to the SMTP Server

See more SMTP Examples

Demonstrates the Chilkat MailMan.SmtpConnect method, which explicitly connects to the SMTP server. If SSL/TLS is required by the current property settings, the secure TLS channel is established as part of connecting. This example opens the connection.

Background: SmtpConnect performs just the connect (and TLS handshake) step, without authenticating — useful when you want fine-grained control over the connection lifecycle, or to separate connecting from authenticating (SmtpAuthenticate) for diagnostics. For everyday sending you don't need to call it: SendEmail connects automatically.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkMailManW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkMailManW mailman;

    success = FALSE;

    //  Demonstrates the MailMan.SmtpConnect method, which explicitly connects to the SMTP server.
    //  If SSL/TLS is required by the current property settings, the secure channel is established
    //  as part of connecting.

    mailman = CkMailManW_Create();

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

    //  Explicitly connect to the SMTP server (does not authenticate).

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

    wprintf(L"Connected to the SMTP server.\n");


    CkMailManW_Dispose(mailman);

    }