PureBasic
PureBasic
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 PureBasic Downloads
IncludeFile "CkMailMan.pb"
Procedure ChilkatExample()
success.i = 0
; 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.
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)
CkMailMan::setCkSmtpUsername(mailman, "user@example.com")
CkMailMan::setCkSmtpPassword(mailman, "myPassword")
; Connect first, then authenticate.
success = CkMailMan::ckSmtpConnect(mailman)
If success = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
ProcedureReturn
EndIf
success = CkMailMan::ckSmtpAuthenticate(mailman)
If success = 0
Debug CkMailMan::ckLastErrorText(mailman)
CkMailMan::ckDispose(mailman)
ProcedureReturn
EndIf
Debug "Authenticated with the SMTP server."
CkMailMan::ckDispose(mailman)
ProcedureReturn
EndProcedure