Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

Example: Email.GetDsnInfo method

See more Email Object Examples

Demonstrates how to call the GetDsnInfo method.

Chilkat Rust Downloads

Rust

let email = chilkat::Email::new();

if email.load_eml("qa_data/eml/sample_multipart_report.eml").is_err() {
    println!("{}", email.last_error_text());
    return;
}

let json = chilkat::JsonObject::new();
if email.get_dsn_info(&json).is_err() {
    println!("{}", email.last_error_text());
    return;
}

json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());

// Sample output:

// {
//   "reporting-mta": "dns; Exchange2016.example.com",
//   "final-recipient": [
//     "herb.butterworth1247692846@gmail.com"
//   ],
//   "action": "failed",
//   "status": "5.1.1",
//   "remote-mta": "dns; mx.google.com",
//   "x-supplementary-info": "<mx.google.com #5.1.1 smtp;550-5.1.1 The email account that you tried to reach does not exist. Please try 550-5.1.1 double-checking the recipient's email address for typos or 550-5.1.1 unnecessary spaces. Learn more at 550 5.1.1  https://support.google.com/mail/?p=NoSuchUser o8-20020a056870968800b001b55816bea9si2188132oaq.70 - gsmtp>",
//   "x-display-name": "herb.butterworth1247692846@gmail.com"
// }

// Code for parsing the JSON:

let reporting_mta = json.string_of("reporting-mta").unwrap_or_default();
let action = json.string_of("action").unwrap_or_default();
let status = json.string_of("status").unwrap_or_default();
let remote_mta = json.string_of("remote-mta").unwrap_or_default();
let x_supplementary_info = json.string_of("x-supplementary-info").unwrap_or_default();
let x_display_name = json.string_of("x-display-name").unwrap_or_default();
let mut i = 0;
let count = json.size_of_array("final-recipient");
while i < count {
    json.set_i(i);
    let _ = json.string_of("final-recipient[i]").unwrap_or_default();
    i = i + 1;
}