Rust
Rust
Permanently Delete a Specific GMail Message
See more GMail REST API Examples
Immediately and permanently deletes the specified message. This operation cannot be undone. (This is not the same as moving a message to Trash.)Chilkat Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
http.set_auth_token("GMAIL-ACCESS-TOKEN");
// The id of the GMail message to delete.
let id = "1669cc9a926bb8c1".to_string();
let user_id = "me".to_string();
let _ = http.set_url_var("userId", "me");
let _ = http.set_url_var("id", &id);
// Delete the email.
let url = "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}".to_string();
let Ok(response_str) = http.quick_delete_str(&url) else {
println!("{}", http.last_error_text());
return;
};
println!("status = {}", http.last_status());
// A 204 response indicate success.
// It is common for HTTP DELETE operations to respond with a 204 status code with an empty body for success.
// You'll find many REST APIs follow this custom..
if http.last_status() != 204 {
println!("{}", response_str);
println!("Failed.");
return;
}
println!("Message deleted!");