Sample code for 30+ languages & platforms
Lua

Upload (Append) Email to an IMAP Mailbox

Upload / append an email to an IMAP mailbox.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local imap = chilkat.Imap.new()

-- Connect to an IMAP server.
-- Use TLS
imap.ssl = true
imap.port = 993
local success = imap:connect("imap.example.com")
if not success then
    print(imap.last_error_text)
    return
end

-- Login
success = imap:login("myLogin", "myPassword")
if not success then
    print(imap.last_error_text)
    return
end

local email = chilkat.Email.new()

-- Load the email from a .eml file.
success = email:load_eml("myEmail.eml")
if not success then
    print(email.last_error_text)
    return
end

success = imap:append_mail("Inbox", email)
if not success then
    print(imap.last_error_text)
    return
end

print("Email uploaded to Inbox!")

-- Disconnect from the IMAP server.
success = imap:disconnect()