Lua
Lua
Amazon SES v2: Look up delivery history for a message ID
See more Amazon SES Examples
Enable Virtual Deliverability Manager for the sending account. Use the SES MessageId from a recent eligible send to a real test mailbox in the same Region. Mailbox simulator sends are excluded from VDM. Events are grouped by destination. Timestamps in the REST response are Unix epoch seconds.
GetMessageInsights · VDM dashboard
Chilkat Lua Downloads
local chilkat = require("chilkat")
-- Assumes Chilkat is unlocked. See Global Unlock Sample.
local success = false
local messageId = "YOUR_SES_MESSAGE_ID"
local path = chilkat.StringBuilder.new()
path:append("/v2/email/insights/")
path:append(messageId)
path:append("/")
-- Use the same AWS Region for the identity, endpoint, and Signature Version 4.
local region = "us-west-2"
local host = chilkat.StringBuilder.new()
host:append("email.")
host:append(region)
host:append(".amazonaws.com")
local signer = chilkat.AuthAws.new()
-- Supply the credentials from your application's credential provider.
signer.access_key = "AWS_ACCESS_KEY_ID"
signer.secret_key = "AWS_SECRET_ACCESS_KEY"
signer.region = region
signer.service_name = "ses"
local connection = chilkat.Socket.new()
connection.require_ssl_cert_verify = true
success = connection:connect(host:get_as_string(), 443, true, 10000)
if not success then
print(connection.last_error_text)
return
end
local rest = chilkat.Rest.new()
success = rest:use_connection(connection, false)
if not success then
print(rest.last_error_text)
return
end
success = rest:set_auth_aws(signer)
if not success then
print(rest.last_error_text)
return
end
-- For temporary AWS credentials, supply the session token from the same provider.
local sessionToken = ""
if sessionToken ~= "" then
rest:add_query_param("X-Amz-Security-Token", sessionToken)
end
local responseText = rest:full_request_no_body("GET", path:get_as_string())
if not rest.last_method_success then
print(rest.last_error_text)
return
end
if rest.response_status_code == 404 then
print("No insights found. Check the Region, message ID, and VDM coverage.")
return
end
if rest.response_status_code ~= 200 then
print("SES returned HTTP " .. rest.response_status_code .. " " .. responseText)
return
end
local response = chilkat.JsonObject.new()
success = response:load(responseText)
if not success then
print(response.last_error_text)
return
end
local i = 0
local recipients = response:size_of_array("Insights")
if recipients < 1 then
print("No recipient history is available yet.")
end
while i < recipients do
response.i = i
print(response:string_of("Insights[i].Destination"))
local j = 0
local count = response:size_of_array("Insights[i].Events")
while j < count do
response.j = j
print(response:string_of("Insights[i].Events[j].Timestamp") .. " " .. response:string_of("Insights[i].Events[j].Type"))
if response:has_member("Insights[i].Events[j].Details.Bounce.DiagnosticCode") then
print(response:string_of("Insights[i].Events[j].Details.Bounce.DiagnosticCode"))
end
if response:has_member("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType") then
print(response:string_of("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType"))
end
j = j + 1
end
i = i + 1
end