Sample code for 30+ languages & platforms
DataFlex

Authenticate with the SMTP Server

See more SMTP Examples

Demonstrates the Chilkat MailMan.SmtpAuthenticate method, which authenticates with the SMTP server using the current SMTP property settings, such as SmtpUsername and SmtpPassword. It is typically called after SmtpConnect. This example connects and then authenticates.

Background: SMTP authentication is a separate step from connecting: after the EHLO handshake, the client proves its identity via the AUTH command using a mechanism the server offers (LOGIN, PLAIN, CRAM-MD5, XOAUTH2, etc.). Splitting connect and authenticate into explicit calls lets you pinpoint exactly which step fails — and hold an authenticated connection open to send many messages efficiently.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoMailman
    String sTemp1

    Move False To iSuccess

    //  Demonstrates the MailMan.SmtpAuthenticate method, which authenticates with the SMTP server
    //  using the current SMTP property settings (such as SmtpUsername and SmtpPassword).  It is
    //  typically called after SmtpConnect.

    Get Create (RefClass(cComChilkatMailMan)) To hoMailman
    If (Not(IsComObjectCreated(hoMailman))) Begin
        Send CreateComObject of hoMailman
    End

    //  Configure the SMTP server connection.
    Set ComSmtpHost Of hoMailman To "smtp.example.com"
    Set ComSmtpPort Of hoMailman To 465
    Set ComSmtpSsl Of hoMailman To True
    Set ComSmtpUsername Of hoMailman To "user@example.com"
    Set ComSmtpPassword Of hoMailman To "myPassword"

    //  Connect first, then authenticate.

    Get ComSmtpConnect Of hoMailman To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComSmtpAuthenticate Of hoMailman To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoMailman To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln "Authenticated with the SMTP server."


End_Procedure