Sample code for 30+ languages & platforms
Lua

Send an Email via SMTP

See more SMTP Examples

Demonstrates the Chilkat MailMan.SendEmail method, which sends a single Email object through the configured SMTP server. This example configures the SMTP connection, builds a message, and sends it.

Background: SMTP (Simple Mail Transfer Protocol) is the protocol for sending mail. The typical flow is: connect to the server, authenticate, then hand over the message with MAIL FROM, RCPT TO, and DATA. SendEmail wraps all of that: you build an Email with subject, recipients, and body, and Chilkat renders it to MIME and delivers it. Modern submission commonly uses implicit TLS on port 465 (SmtpSsl = true).

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- Demonstrates the MailMan.SendEmail method, which sends a single Email object through the
-- configured SMTP server.

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"

-- Build the email to send.
local email = chilkat.Email.new()
email.subject = "Test email from Chilkat"
email.from = "alice@example.com"
email:add_to("Bob", "bob@example.com")
email.body = "Hello, this is a test message."

-- Send the email.

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

print("Email sent.")

-- Note: Explicitly connecting/authenticating is optional.  Chilkat MailMan automatically
-- connects and authenticates -- using the property settings above -- whenever a server
-- operation requires it.  Calling the explicit connect/authenticate methods can still be
-- helpful to determine whether a failure occurs while connecting or while authenticating.