Lua
Lua
SMTP Send Raw Command
Demonstrates how to send a raw command to the SMTP server after the connecting and authenticating.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 mailman = chilkat.MailMan.new()
mailman.smtp_host = "smtp.mail.us-west-2.awsapps.com"
mailman.smtp_ssl = true
mailman.smtp_port = 465
local success = mailman:smtp_connect()
if not success then
print(mailman.last_error_text)
return
end
mailman.smtp_username = "john@example.com"
mailman.smtp_password = "the_password"
success = mailman:smtp_authenticate()
if not success then
print(mailman.last_error_text)
return
end
print("Authenticated!")
-- Send the "EHLO" command again to get the multi-line response that includes the SMTP capabilities.
-- The capabilities are the lines in the response that begin with "250-".
local responseStr = mailman:smtp_send_raw_command("EHLO client.example.com", "utf-8", false)
if not mailman.last_method_success then
print(mailman.last_error_text)
return
end
print(responseStr)
-- A sample response:
-- 250-smtp.us-west-2.mail.awsapps.com
-- 250-8BITMIME
-- 250-AUTH PLAIN LOGIN
-- 250 Ok