Lua
Lua
SMTP XOAUTH2 Authentication
See more SMTP Examples
Demonstrates how to authenticate using an OAuth2 access token. This example assumes you have already obtained the access token and now wish to use it in an SMTP session.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local oauth2_access_token = "some_previously_obtained_token"
local mailman = chilkat.MailMan.new()
-- Set the properties for the SMTP server, whatever they may be..
mailman.smtp_host = "smtp.example.com"
mailman.smtp_port = 587
mailman.start_tls = true
mailman.smtp_username = "myLogin"
mailman.oauth2_access_token = oauth2_access_token
-- Create a new email object
local email = chilkat.Email.new()
email.subject = "This is a test"
email.body = "This is a test"
email.from = "Joe Example <joe@example.com>"
email:add_to("Chilkat Admin", "admin@chilkatsoft.com")
-- Connect to the server indicated by the SmtpHost property
local success = mailman:smtp_connect()
if not success then
print(mailman.last_error_text)
return
end
-- Authenticate using XOAUTH2 (using the OAuth2AccessToken)
success = mailman:smtp_authenticate()
if not success then
print(mailman.last_error_text)
return
end
success = mailman:send_email(email)
if not success then
print(mailman.last_error_text)
return
end
print("Email sent.")
mailman:close_smtp_connection()