Search code examples
javagoogle-apigmailgmail-apigoogle-api-java-client

Inserting a deleted message to gmail with Java's API


I want to send a deleted message to gmail, I'm using java libraries and I got the quick start to work and send regular email to my inbox, but I don't see where to add that property.

enter image description here

I'm using the example code from here:

https://developers.google.com/gmail/api/v1/reference/users/messages/insert


Solution

  • The insert message method has an optional parameter for that lets you set deleted. Optional parameters have extra methods that can be used to apply them to the main request.

    deleted boolean Mark the email as permanently deleted (not TRASH) and only visible in Google Vault to a Vault administrator. Only used for G Suite accounts. (Default: false)

    Example:

    request = service.users().messages().insert(userId, message)
    request.setdeleted(True);
    request.execute();
    

    Link to documentation for setDeleted