Sample code for 30+ languages & platforms
Lua

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

Lua
local chilkat = require("chilkat")

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

local mailman = chilkat.MailMan.new()

-- Configure the SMTP server connection.
mailman.smtp_host = "smtp.example.com"
mailman.smtp_port = 465
mailman.smtp_ssl = true
mailman.smtp_username = "user@example.com"
mailman.smtp_password = "myPassword"

-- Connect first, then authenticate.

local success = mailman:smtp_connect()
if not success then
    print(mailman.last_error_text)
    return
end

success = mailman:smtp_authenticate()
if not success then
    print(mailman.last_error_text)
    return
end

print("Authenticated with the SMTP server.")