{"id":297,"date":"2024-07-30T19:09:24","date_gmt":"2024-07-30T19:09:24","guid":{"rendered":"https:\/\/duff.io\/?p=297"},"modified":"2024-07-30T19:09:24","modified_gmt":"2024-07-30T19:09:24","slug":"deleting-accidental-or-dangerous-emails-in-google-workspace","status":"publish","type":"post","link":"https:\/\/duff.io\/?p=297","title":{"rendered":"Deleting accidental or dangerous emails in Google Workspace"},"content":{"rendered":"\n<p>As Google Workspace admins, sometimes, we are asked to delete emails from other users accounts when the messages are sent in error or contain malware\/phishing\/etc. This is not something we do lightly and should only be done in the most extreme cases. <\/p>\n\n\n\n<p>If the message went outside your Google Workspace domain, there is almost nothing we can do beyond asking the recipient to delete the message.<\/p>\n\n\n\n<p>For messages received inside of the Google Workspace, there are two things I&#8217;ve done:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Change the recipient&#8217;s password, delete the message, empty the trash;<\/li>\n\n\n\n<li>Use the command line tool GAM<\/li>\n<\/ol>\n\n\n\n<p>The remainder of this post focuses on the second approach since it is less disruptive to the user(s). However, it is more dangerous since mistakes can delete the wrong message(s). When this document refers to GAM, we are referring to the <a href=\"https:\/\/github.com\/taers232c\/GAMADV-XTD3\">GAMADV-XTD3<\/a> version.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Finding the Message ID<\/h2>\n\n\n\n<p>To delete a message using GAM you need to know the Message ID. There are several ways to do this. The easiest is if you have access to an account the message was sent or received from, and then you can use the \u201cShow original\u201d feature of Gmail, find it in the raw headers of an email, or use GAM to search for it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u201cShow original\u201d feature of Gmail to find a Message ID<\/h3>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"743\" src=\"https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-1024x743.png\" alt=\"\" class=\"wp-image-298\" srcset=\"https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-1024x743.png 1024w, https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-300x218.png 300w, https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-768x557.png 768w, https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image.png 1505w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In Gmail, select \u201cShow original\u201d which will nicely decode the headers of the message and show you the Message ID in the first line:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"438\" src=\"https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-1-1024x438.png\" alt=\"\" class=\"wp-image-299\" srcset=\"https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-1-1024x438.png 1024w, https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-1-300x128.png 300w, https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-1-768x328.png 768w, https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-1-1536x657.png 1536w, https:\/\/duff.io\/wp-content\/uploads\/2024\/07\/image-1-2048x876.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Tip: You can ask the sender to do this in their sent message folder and copy\/paste the Message ID in an email to you.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Looking at the raw headers \/ original email to find a Message ID<\/h3>\n\n\n\n<p>If you have access to the original unparsed email message (either from the sender or a recipient), you can look through the headers at the top of the message for a line that starts with \u201cMessage-ID:\u201d<\/p>\n\n\n\n<p>Here is an example of the headers from an email that an email client hasn\u2019t parsed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Message-ID: &lt;0101018d3c6c1777-3b5e6fe4-a6f7-4c0f-bxc1-75850bcb519e-000000@us-west-2.amazonses.com><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Using GAM to find a Message ID<\/h3>\n\n\n\n<p>GAM has a few ways to search for a Message ID. See the <a href=\"https:\/\/sites.google.com\/jis.edu.bn\/gam-commands\/services\/gmail#h.8fjnq8kcsk35\">Print Messages Query<\/a> section of the GAM manual.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Searching by subject and date range in a single users account<\/h4>\n\n\n\n<p>The following commands searches through the account \u201cmyemail\u201d for message with a subject of \u201cAlert for MYNET &#8211; wireless\u201d between 1\/24\/24 and 1\/25\/24. Note that you have to escape the quotes around the subject with a backslash and put the date in YYYY-MM-DD format.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gam user myemail show messages query \"subject:\\\"Alert for MYNET - wireless\\\" before:2024-01-25 after:2024-01-24\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Searching by subject and date range in all accounts and send the results to a new Google Sheet<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>gam all users print messages query \"subject:\\\"Alert for MYNET - wireless\\\" before:2024-01-25 after:2024-01-24\" todrive<\/code><\/pre>\n\n\n\n<p>This is going to be slow (think 30-45 minutes) since it searches each account one at a time. You can also use \u201cgam ou_and_children_ns\u00a0<strong>&lt;Path\/To\/OU><\/strong>\u201d instead of \u201call users\u201d to just search a single OU. Since the message ID is going to be the same for all users, you can often just search one user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Deleting an email using GAM<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">From a single user<\/h3>\n\n\n\n<p>The folllowing command will delete from the user myemail the message that matches Message ID specified after \u201crfc822msgid:\u201d (in this case <a href=\"mailto:0101018d3c6c1777-3b5e6fe0-a6f7-4c0f-bcc1-75859bbb519e-000000@us-west-2.amazonses.com\">0101018d3c6c1777-3b5e6fe4-a6f7-4c0f-bxc1-75850bcb519e-000000@us-west-2.amazonses.com<\/a>).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gam user myemail delete messages query \"rfc822msgid:0101018d3c6c1777-3b5e6fe4-a6f7-4c0f-bxc1-75850bcb519e-000000@us-west-2.amazonses.com\" doit<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">From all users<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gam all users delete messages query \"rfc822msgid:0101018d3c6c1777-3b5e6fe4-a6f7-4c0f-bxc1-75850bcb519e-000000@us-west-2.amazonses.com\" doit<\/code><\/pre>\n\n\n\n<p>Just like with searching all users, deleting from all users is very slow (30-45 minutes) since it iterates through all of our users. You can also target an OU (<a href=\"https:\/\/sites.google.com\/jis.edu.bn\/gam-commands\/services\/gmail#h.8fjnq8kcsk35\">see documentation<\/a>) if needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">From a group of users<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gam group mygroup@mygoogleworkspace.org delete messages query \"rfc822msgid:0101018d3c6c1777-3b5e6fe4-a6f7-4c0f-bxc1-75850bcb519e-000000@us-west-2.amazonses.com\" doit<\/code><\/pre>\n\n\n\n<p>Like all users, this will iterate through all members of the group and can take a while to run on large groups. The message specified in the query does not have to have been sent to the list. The command is only using the group for the list of accounts to search through and delete the message from.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>As Google Workspace admins, sometimes, we are asked to delete emails from other users accounts when the messages are sent in error or contain malware\/phishing\/etc. This is not something we do lightly and should only be done in the most extreme cases. If the message went outside your Google Workspace domain, there is almost nothing [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[22,21],"tags":[],"class_list":["post-297","post","type-post","status-publish","format-standard","hentry","category-gam","category-google-workspace"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/duff.io\/index.php?rest_route=\/wp\/v2\/posts\/297","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/duff.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/duff.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/duff.io\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/duff.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=297"}],"version-history":[{"count":1,"href":"https:\/\/duff.io\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions"}],"predecessor-version":[{"id":300,"href":"https:\/\/duff.io\/index.php?rest_route=\/wp\/v2\/posts\/297\/revisions\/300"}],"wp:attachment":[{"href":"https:\/\/duff.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=297"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/duff.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=297"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/duff.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}