Rust
Rust
Amazon SES v2: Verify a sending domain with Easy DKIM
See more Amazon SES Examples
Use a domain you control. Run once to create the regional identity, publish the returned CNAMEs with your DNS provider, then set checkExisting to true and run again to read the status. The target suffix comes from SES. If your DNS provider appends the domain automatically, enter just the relative record name.
CreateEmailIdentity · GetEmailIdentity · Easy DKIM records
Chilkat Rust Downloads
// Assumes Chilkat is unlocked. See Global Unlock Sample.
let _ = false;
let domain_name = "example.com".to_string();
let check_existing = 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(®ion);
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(®ion);
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 mut response_text = String::new();
if check_existing {
let path = chilkat::StringBuilder::new();
let _ = path.append("/v2/email/identities/");
let _ = path.append(&domain_name);
response_text = rest.full_request_no_body("GET", &path.get_as_string().unwrap_or_default()).unwrap_or_default();
} else {
let identity = chilkat::JsonObject::new();
let _ = identity.update_string("EmailIdentity", &domain_name);
let _ = rest.add_header("Content-Type", "application/json");
response_text = rest.full_request_string("POST", "/v2/email/identities", &identity.emit().unwrap_or_default()).unwrap_or_default();
}
if !rest.last_method_success() {
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!("DKIM status: {}", response.string_of("DkimAttributes.Status").unwrap_or_default());
println!("Verified for sending: {}", response.bool_of("VerifiedForSendingStatus"));
let count = response.size_of_array("DkimAttributes.Tokens");
if count < 1 {
println!("No Easy DKIM tokens were returned. Check this identity's DKIM configuration.");
return;
}
if !response.has_member("DkimAttributes.SigningHostedZone") {
println!("Find the CNAME targets for this identity in the SES console.");
return;
}
let zone = response.string_of("DkimAttributes.SigningHostedZone").unwrap_or_default();
let mut i = 0;
while i < count {
response.set_i(i);
let token = response.string_of("DkimAttributes.Tokens[i]").unwrap_or_default();
println!("{}._domainkey.{} CNAME {}.{}", token, domain_name, token, zone);
i = i + 1;
}