Sample code for 30+ languages & platforms
Rust

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 Rust Downloads

Rust

// Assumes Chilkat is unlocked. See Global Unlock Sample.
let _ = false;

let message_id = "YOUR_SES_MESSAGE_ID".to_string();
let path = chilkat::StringBuilder::new();
let _ = path.append("/v2/email/insights/");
let _ = path.append(&message_id);
let _ = path.append("/");
// Use the same AWS Region for the identity, endpoint, and Signature Version 4.
let region = "us-west-2".to_string();
let host = chilkat::StringBuilder::new();
let _ = host.append("email.");
let _ = host.append(&region);
let _ = host.append(".amazonaws.com");

let signer = chilkat::AuthAws::new();
// Supply the credentials from your application's credential provider.
signer.set_access_key("AWS_ACCESS_KEY_ID");
signer.set_secret_key("AWS_SECRET_ACCESS_KEY");
signer.set_region(&region);
signer.set_service_name("ses");

let connection = chilkat::Socket::new();
connection.set_require_ssl_cert_verify(true);
if connection.connect(&host.get_as_string().unwrap_or_default(), 443, true, 10000).is_err() {
    println!("{}", connection.last_error_text());
    return;
}

let rest = chilkat::Rest::new();
if rest.use_connection(&connection, false).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

if rest.set_auth_aws(&signer).is_err() {
    println!("{}", rest.last_error_text());
    return;
}

// For temporary AWS credentials, supply the session token from the same provider.
let session_token = String::new();
if session_token != "" {
    let _ = rest.add_query_param("X-Amz-Security-Token", &session_token);
}

let Ok(response_text) = rest.full_request_no_body("GET", &path.get_as_string().unwrap_or_default()) else {
    println!("{}", rest.last_error_text());
    return;
};

if rest.response_status_code() == 404 {
    println!("No insights found. Check the Region, message ID, and VDM coverage.");
    return;
}

if rest.response_status_code() != 200 {
    println!("SES returned HTTP {} {}", rest.response_status_code(), response_text);
    return;
}

let response = chilkat::JsonObject::new();
if response.load(&response_text).is_err() {
    println!("{}", response.last_error_text());
    return;
}

let mut i = 0;
let recipients = response.size_of_array("Insights");
if recipients < 1 {
    println!("No recipient history is available yet.");
}

while i < recipients {
    response.set_i(i);
    println!("{}", response.string_of("Insights[i].Destination").unwrap_or_default());
    let mut j = 0;
    let count = response.size_of_array("Insights[i].Events");
    while j < count {
        response.set_j(j);
        println!("{} {}", response.string_of("Insights[i].Events[j].Timestamp").unwrap_or_default(), response.string_of("Insights[i].Events[j].Type").unwrap_or_default());
        if response.has_member("Insights[i].Events[j].Details.Bounce.DiagnosticCode") {
            println!("{}", response.string_of("Insights[i].Events[j].Details.Bounce.DiagnosticCode").unwrap_or_default());
        }

        if response.has_member("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType") {
            println!("{}", response.string_of("Insights[i].Events[j].Details.Complaint.ComplaintFeedbackType").unwrap_or_default());
        }

        j = j + 1;
    }

    i = i + 1;
}