Lua
Lua
Embed Image in HTML Email
Demonstrates how to create and send an HTML email with an embedded image.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.
-- The mailman object is used for sending and receiving email.
local mailman = chilkat.MailMan.new()
-- Set the SMTP server.
mailman.smtp_host = "smtp.comcast.net"
-- Create a new email object
local email = chilkat.Email.new()
-- Add an embedded image to the HTML email.
local fileOnDisk = "images/dude2.gif"
local filePathInHtml = "dudeAbc.gif"
-- Embed the GIF image in the email.
local success = email:add_related_file2(fileOnDisk, filePathInHtml)
if not success then
print(mailman.last_error_text)
return
end
-- The src attribute for the image tag is set to the filePathInHtml:
local htmlBody = "<html><body>Embedded Image:<br><img src=\"dudeAbc.gif\"></body></html>"
-- Set the basic email stuff: HTML body, subject, "from", "to";
email:set_html_body(htmlBody)
email.subject = "Lua HTML email with an embedded image."
success = email:add_to("Admin", "admin@chilkatsoft.com")
email.from = "Chilkat Support <support@chilkatsoft.com>"
success = mailman:send_email(email)
if not success then
print(mailman.last_error_text)
else
print("Mail Sent!")
end