Dart
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final http = CkHttp();
http.authToken = 'GMAIL-ACCESS-TOKEN';
// The id of the GMail message to delete.
final id = '1669cc9a926bb8c1';
final userId = 'me';
http.setUrlVar('userId', 'me');
http.setUrlVar('id', id);
// Delete the email.
final url = 'https://www.googleapis.com/gmail/v1/users/{\$userId}/messages/{\$id}';
final String responseStr;
try {
responseStr = http.quickDeleteStr(url);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('status = ${http.lastStatus}');
// 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.lastStatus != 204) {
print(responseStr);
print('Failed.');
return;
}
print('Message deleted!');
}