Sample code for 30+ languages & platforms
Lua

Upload .eml File to an IMAP Mailbox

See more IMAP Examples

Demonstrates how to upload the MIME source of an email to a mailbox on an IMAP server.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local imap = chilkat.Imap.new()

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

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

-- Login
success = imap:login("MY-IMAP-LOGIN", "MY-IMAP-PASSWORD")
if not success then
    print(imap.last_error_text)
    return
end

local sbMime = chilkat.StringBuilder.new()
sbMime:load_file("qa_data/eml/emoji_pizza.eml", "utf-8")

-- Upload to the mailbox.
success = imap:append_mime("[Gmail]/testFolder", sbMime:get_as_string())
if not success then
    print(imap.last_error_text)
    return
end

imap:disconnect()

print("OK.")