Sample code for 30+ languages & platforms
Rust

Amazon SES v2: Check regional sending access and quota

See more Amazon SES Examples

Run this in the Region where your application sends mail. Check whether SES accepts sends, whether the account has production access, and how much of its rolling 24-hour quota is in use. Sandbox accounts can send to verified recipients and the mailbox simulator. Sender verification is regional.

GetAccount · Sandbox restrictions

Chilkat Rust Downloads

Rust

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

// 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", "/v2/email/account") else {
    println!("{}", rest.last_error_text());
    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;
}

println!("Sending enabled: {}", response.bool_of("SendingEnabled"));
println!("Production access: {}", response.bool_of("ProductionAccessEnabled"));
println!("Recipients sent to in the last 24 hours: {}", response.string_of("SendQuota.SentLast24Hours").unwrap_or_default());
println!("24-hour recipient quota (-1 means unlimited): {}", response.string_of("SendQuota.Max24HourSend").unwrap_or_default());
println!("Maximum recipients per second: {}", response.string_of("SendQuota.MaxSendRate").unwrap_or_default());