Sample code for 30+ languages & platforms
Lua Requires Chilkat v9.5.0.71+

POP3 Login Secure

Demonstrates how to set the POP3 password using a secure string.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

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

local mailman = chilkat.MailMan.new()

-- Imagine we've previously saved our encrypted login and password within a JSON config file
-- that contains this:

-- {
--   "pop3_login": "D7lnlWY291LKMeChlvQq7N/Tg7ieuSB15a+9Ekyd0R4=",
--   "pop3_password": "5neIq9Jmn0E3p71N6Yc8TA=="
-- }

local json = chilkat.JsonObject.new()
json:load_file("qa_data/passwords/pop3.json")

local crypt = chilkat.Crypt2.new()

-- These are the encryption settings we previously used to encrypt the credentials within the JSON config file.
crypt.crypt_algorithm = "aes"
crypt.cipher_mode = "cbc"
crypt.key_length = 128
crypt:set_encoded_key("000102030405060708090A0B0C0D0E0F", "hex")
crypt:set_encoded_iv("000102030405060708090A0B0C0D0E0F", "hex")
crypt.encoding_mode = "base64"

local ssLogin = chilkat.SecureString.new()
local ssPassword = chilkat.SecureString.new()

-- Decrypt to the secure string.  (the strings will still held in memory encrypted, but are now encrypted using
-- a randomly generated session key.)
crypt:decrypt_secure_enc(json:string_of("pop3_login"), ssLogin)
crypt:decrypt_secure_enc(json:string_of("pop3_password"), ssPassword)

-- Set the POP3 domain, login, and password
mailman.mail_host = "pop.gmail.com"
mailman.pop_ssl = true
mailman.mail_port = 995

mailman.pop_username = ssLogin:access()
-- Set the PopPassword property via the SetPassword method using the secure string.
mailman:set_password("pop3", ssPassword)

-- Connect and authenticate..
local success = mailman:pop3_connect()
if not success then
    print(mailman.last_error_text)
    return
end

success = mailman:pop3_authenticate()
if not success then
    print(mailman.last_error_text)
    return
end

print("POP3 login successful.")

local numMessages = mailman:get_mailbox_count()
if numMessages < 0 then
    print(mailman.last_error_text)
    return
end

print("Num messages in Inbox = " .. numMessages)

mailman:pop3_end_session()