Lua
Lua
Append MIME with Initial IMAP Flags
See more IMAP Examples
Demonstrates the Chilkat Imap.AppendMimeWithFlags method, which uploads a MIME message and sets its initial system flags. The first argument is the mailbox and the second is the MIME text. The third through sixth arguments control \Seen, \Flagged, \Answered, and \Draft respectively — pass true to set a flag. This example uploads a message that is already marked read.
Background: When importing or archiving mail you frequently want the uploaded message to arrive in a particular state — already read, pre-flagged, or marked as a draft. Setting the flags at append time is a single operation, avoiding a second
STORE round trip. These explicit arguments take precedence over the AppendSeen property.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Demonstrates the Imap.AppendMimeWithFlags method, which uploads a MIME message and sets its
-- initial system flags. The 1st argument is the mailbox, the 2nd is the MIME text, and the
-- 3rd through 6th arguments set the \Seen, \Flagged, \Answered, and \Draft flags.
local imap = chilkat.Imap.new()
imap.ssl = true
imap.port = 993
local success = imap:connect("imap.example.com")
if not success then
print(imap.last_error_text)
return
end
success = imap:login("user@example.com", "myPassword")
if not success then
print(imap.last_error_text)
return
end
-- Build the email to be uploaded.
local email = chilkat.Email.new()
email.subject = "Meeting agenda"
email.from = "Alice <alice@example.com>"
success = email:add_to("Bob", "bob@example.com")
email.body = "Let's meet at 10am to review the agenda."
local mimeText = email:get_mime()
if not email.last_method_success then
print(email.last_error_text)
return
end
-- Choose the initial flags. Named variables make each argument's meaning clear at the call.
local seen = true
local flagged = false
local answered = false
local draft = false
-- Upload to the Inbox already marked as read (\Seen), with the other flags unset.
success = imap:append_mime_with_flags("Inbox", mimeText, seen, flagged, answered, draft)
if not success then
print(imap.last_error_text)
return
end
print("Appended UID: " .. imap.append_uid)
success = imap:disconnect()
if not success then
print(imap.last_error_text)
return
end