Sample code for 30+ languages & platforms
PureBasic

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

PureBasic
IncludeFile "CkMailMan.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  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.i = CkMailMan::ckCreate()
    If mailman.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Configure the SMTP server connection.
    CkMailMan::setCkSmtpHost(mailman, "smtp.example.com")
    CkMailMan::setCkSmtpPort(mailman, 465)
    CkMailMan::setCkSmtpSsl(mailman, 1)

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

    success = CkMailMan::ckSmtpConnect(mailman)
    If success = 0
        Debug CkMailMan::ckLastErrorText(mailman)
        CkMailMan::ckDispose(mailman)
        ProcedureReturn
    EndIf

    Debug "Connected to the SMTP server."


    CkMailMan::ckDispose(mailman)


    ProcedureReturn
EndProcedure