{"id":575,"date":"2015-09-04T12:00:37","date_gmt":"2015-09-04T10:00:37","guid":{"rendered":"http:\/\/www.limilabs.com\/blog\/?p=575"},"modified":"2023-03-03T10:04:34","modified_gmt":"2023-03-03T08:04:34","slug":"delete-email-permanently-in-gmail","status":"publish","type":"post","link":"https:\/\/www.limilabs.com\/blog\/delete-email-permanently-in-gmail","title":{"rendered":"Delete email permanently in Gmail"},"content":{"rendered":"\n<div class=\"wp-block-image\"><figure class=\"alignleft\"><img loading=\"lazy\" decoding=\"async\" width=\"131\" height=\"61\" src=\"\/blog\/wp-content\/uploads\/2009\/11\/gmail.png\" alt=\"\" class=\"wp-image-271\" title=\"gmail\"\/><\/figure><\/div>\n\n\n\n<p>If you delete a message from your Inbox or one of your custom folders, <strong>it will still appear in [Gmail]\/All Mail<\/strong>.<\/p>\n\n\n\n<p>Here&#8217;s why: in most folders, <strong>deleting a message simply removes that folder&#8217;s label from the message<\/strong>, including the label identifying the message as being in your Inbox.<\/p>\n\n\n\n<p>[Gmail]\/All Mail shows all of your messages, whether or not they have labels attached to them.<\/p>\n\n\n\n<p>If you want to<strong> permanently delete a message<\/strong> from all folders:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>Move it to the [Gmail]\/Trash<\/strong> folder (or [Gmail]\/Bin or national version).<\/li><li><strong>Delete it<\/strong> from the [Gmail]\/Trash folder (or [Gmail]\/Bin or national version).<\/li><\/ol>\n\n\n\n<p>All emails in [Gmail]\/Spam and [Gmail]\/Trash are deleted after 30 days.<br>If you delete a message from [Gmail]\/Spam or [Gmail]\/Trash, it will be deleted permanently.<\/p>\n\n\n\n<p>Here&#8217;s how this looks like using Mail.dll <a href=\"\/mail\">.NET IMAP component<\/a>:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Delete emails permanently (C# version)<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/ C# version:\n\nusing(Imap imap = new Imap())\n{\n\timap.ConnectSSL(&quot;imap.gmail.com&quot;);\n\timap.UseBestLogin(&quot;user@gmail.com&quot;, &quot;password&quot;);\n\n\t\/\/ Recognize Trash folder\n\tList&lt;FolderInfo&gt; folders = imap.GetFolders();\n \tCommonFolders common = new CommonFolders(folders);\n \tFolderInfo trash = common.Trash;\n\n\t\/\/ Find all emails we want to delete\n\timap.SelectInbox();\n\tList&lt;long&gt; uids = imap.Search(\n\t\tExpression.Subject(&quot;email to delete&quot;));\n\n\t\/\/ Move email to Trash\n\tList&lt;long&gt; uidsInTrash = new List&lt;long&gt;();\n\tforeach (long uid in uids)\n\t{\n\t\tlong uidInTrash = (long)imap.MoveByUID(uid, trash);\n\t\tuidsInTrash.Add(uidInTrash);\n\t}\n\n\t\/\/ Delete moved emails from Trash\n\timap.Select(trash);\n\tforeach (long uid in uidsInTrash)\n\t{\n\t\timap.DeleteMessageByUID(uid);\n\t}\n\n\timap.Close();\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">Delete emails permanently (VB.NET version)<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\nUsing imap As New Imap()\n\timap.ConnectSSL(\"imap.gmail.com\")\n\timap.UseBestLogin(\"user@gmail.com\", \"password\")\n\n\t' Recognize Trash folder\n\tDim folders As List(Of FolderInfo) = imap.GetFolders()\n\tDim common As CommonFolders = new CommonFolders(folders)\n\tDim trash As FolderInfo = common.Trash\n\n\t' Find all emails we want to delete\n\timap.SelectInbox()\n\tDim uids As List(Of Long) = imap.Search( _\n\t\tExpression.Subject(\"email to delete\"))\n\n\t' Move email to Trash\n\tDim uidsInTrash As New List(Of Long)\n\tFor Each uid As Long In uids\n\t\tDim uidInTrash As Long = imap.MoveByUID(uid,trash)\n\t\tuidsInTrash.Add(uidInTrash)\n\tNext\n\n\t' Delete moved emails from Trash\n\timap.&#x5B;Select](trash)\n\tFor Each uid As Long In uidsInTrash\n\t\timap.DeleteMessageByUID(uid)\n\tNext\n\n\timap.Close()\nEnd Using\n<\/pre><\/div>\n\n\n<p>You can also use <strong>bulk methods<\/strong> to handle large amount of emails faster:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Delete emails permanently in bulk (C# version)<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nusing(Imap imap = new Imap())\n{\n\timap.ConnectSSL(&quot;imap.gmail.com&quot;);\n\timap.UseBestLogin(&quot;user@gmail.com&quot;, &quot;password&quot;);\n\n\t\/\/ Recognize Trash folder\n\tList&lt;FolderInfo&gt; folders = imap.GetFolders();\n \tCommonFolders common = new CommonFolders(folders);\n \tFolderInfo trash = common.Trash;\n\n\t\/\/ Find all emails we want to delete\n\timap.SelectInbox();\n\tList&lt;long&gt; uids = imap.Search(\n\t\tExpression.Subject(&quot;email to delete&quot;));\n\n\t\/\/ Move emails to Trash\n\tList&lt;long&gt; uidsInTrash = imap.MoveByUID(uids, trash);\n\n\t\/\/ Delete moved emails from Trash\n\timap.Select(trash);\n\timap.DeleteMessageByUID(uidsInTrash);\n\n\timap.Close();\n}\n<\/pre><\/div>\n\n\n<h4 class=\"wp-block-heading\">Delete emails permanently in bulk (VB.NET version)<\/h4>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: vb; title: ; notranslate\" title=\"\">\nUsing imap As New Imap()\n\timap.ConnectSSL(\"imap.gmail.com\")\n\timap.UseBestLogin(\"user@gmail.com\", \"password\")\n\n\t' Recognize Trash folder\n\tDim folders As List(Of FolderInfo) = imap.GetFolders()\n\tDim common As CommonFolders = new CommonFolders(folders)\n\tDim trash As FolderInfo = common.Trash\n\n\t' Find all emails we want to delete\n\timap.SelectInbox()\n\tDim uids As List(Of Long) = imap.Search( _\n\t\tExpression.Subject(\"email to delete\"))\n\n\t' Move email to Trash\n\tDim uidsInTrash As List(Of Long) = imap.MoveByUID(uids, trash)\n\n\t' Delete moved emails from Trash\n\timap.&#x5B;Select](trash)\n\timap.DeleteMessageByUID(uidsInTrash)\n\n\timap.Close()\nEnd Using\n<\/pre><\/div>\n\n\n<p>Please also note that there are 2 additional sections in the &#8220;Gmail settings&#8221;\/&#8221;Forwarding and POP\/IMAP&#8221; tab:<\/p>\n\n\n\n<p>&#8220;When I mark a message in IMAP as deleted:&#8221;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Auto-Expunge on &#8211; Immediately update the server. (default)<\/li><li>Expunge off &#8211; Wait for the client to update the server.<\/li><\/ul>\n\n\n\n<p>&#8220;When a message is marked as deleted and expunged from the last visible IMAP folder:&#8221;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Archive the message (default)<\/li><li>Move the message to the Trash<\/li><li>Immediately delete the message forever<\/li><\/ul>\n\n\n\n<p>Those settings change the default behavior of the account and modify DeleteMessage* methods behavior.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you delete a message from your Inbox or one of your custom folders, it will still appear in [Gmail]\/All Mail. Here&#8217;s why: in most folders, deleting a message simply removes that folder&#8217;s label from the message, including the label identifying the message as being in your Inbox. [Gmail]\/All Mail shows all of your messages, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[15,25,28,77,57],"class_list":["post-575","post","type-post","status-publish","format-standard","hentry","category-mail-dll","tag-c","tag-gmail","tag-imap","tag-imap-component","tag-vb-net"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/575"}],"collection":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/comments?post=575"}],"version-history":[{"count":16,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/575\/revisions"}],"predecessor-version":[{"id":6440,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/posts\/575\/revisions\/6440"}],"wp:attachment":[{"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/media?parent=575"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/categories?post=575"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.limilabs.com\/blog\/wp-json\/wp\/v2\/tags?post=575"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}