title: Delete Gmail emails programmatically
body: <p>I am working on an application in which I am accessing Gmail emails in my own application, but I am unable to delete those emails through their id. How can I do this?</p>
  
  <pre><code>delete.setOnClickListener(new OnClickListener() {
  
      @Override
      public void onClick(View arg0) {
          // TODO Auto-generated method stub
          try {
              Uri uri = Uri.parse((new StringBuilder()).append(
                  "content://gmail-ls/messages/").append(account_name).append("/").append(mail_id).toString());
              getContentResolver().delete(uri, null, null);
              Toast.makeText(cont, "Deleted", Toast.LENGTH_SHORT).show();
  
              // getContentResolver().delete(
              // Uri.parse("content://gmail-ls/conversations/"
              // + account_name + "/" + mail_id + ""), null,
              // null);
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
  });
  </code></pre>