Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Mailman

li_Success = 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.

loo_Mailman = create oleobject
li_rc = loo_Mailman.ConnectToNewObject("Chilkat.MailMan")
if li_rc < 0 then
    destroy loo_Mailman
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Configure the SMTP server connection.
loo_Mailman.SmtpHost = "smtp.example.com"
loo_Mailman.SmtpPort = 465
loo_Mailman.SmtpSsl = 1
loo_Mailman.SmtpUsername = "user@example.com"
loo_Mailman.SmtpPassword = "myPassword"

//  Connect first, then authenticate.

li_Success = loo_Mailman.SmtpConnect()
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if

li_Success = loo_Mailman.SmtpAuthenticate()
if li_Success = 0 then
    Write-Debug loo_Mailman.LastErrorText
    destroy loo_Mailman
    return
end if

Write-Debug "Authenticated with the SMTP server."


destroy loo_Mailman