Rust
Rust
Move a GMail Message to Trash
See more GMail REST API Examples
Moves a specific GMail email 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 move to Trash.
let id = "16678c485e7f0a0c".to_string();
let user_id = "me".to_string();
let _ = http.set_url_var("userId", "me");
let _ = http.set_url_var("id", &id);
// Move to trash by POSTing w/ an empty request body.
let url = "https://www.googleapis.com/gmail/v1/users/{$userId}/messages/{$id}/trash".to_string();
let resp = chilkat::HttpResponse::new();
if http.http_str("POST", &url, "", "", "", &resp).is_err() {
println!("{}", http.last_error_text());
return;
}
println!("status = {}", resp.status_code());
// A 200 response status indicate success.
if resp.status_code() != 200 {
println!("{}", resp.body_str());
println!("Failed.");
return;
}
// A successful repsonse contains JSON that looks like this:
// {
// "id": "16678c485e7f0a0c",
// "threadId": "16678c485e7f0a0c",
// "labelIds": [
// "TRASH",
// "CATEGORY_SOCIAL"
// ]
// }
println!("response body:");
println!("{}", resp.body_str());
println!("Message moved to trash!");