{"id":17045,"date":"2025-01-05T12:53:02","date_gmt":"2025-01-05T03:53:02","guid":{"rendered":"https:\/\/84office.jp\/?p=17045"},"modified":"2025-01-05T12:53:03","modified_gmt":"2025-01-05T03:53:03","slug":"gmail-transcript","status":"publish","type":"post","link":"https:\/\/84office.jp\/en\/gmail-transcript\/","title":{"rendered":"Streamline Your Workflow with Google Apps Script: Easily Transfer Gmail Content to Google Sheets"},"content":{"rendered":"<div class=\"codoc-evacuations\" style=\"display:none;\" data-shortcode=\"\"><\/div>\n<p class=\"wp-block-paragraph\">Do you find it time-consuming and tedious to manually transfer information received in Gmail to a Google Sheet?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When you need to extract only the necessary information from numerous emails, copying and pasting manually can significantly lower your work efficiency.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we\u2019ll introduce a method to automatically transfer Gmail content to a Google Sheet using Google Apps Script.<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-60 wp-block-paragraph\">By leveraging Google Apps Script, you can streamline your tasks and eliminate wasted time.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Example Output<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large u-mb-ctrl u-mb-50\"><img decoding=\"async\" width=\"1024\" height=\"417\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-1024x417.png\" alt=\"\" class=\"wp-image-17036\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-1024x417.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-300x122.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-768x313.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-1536x626.png 1536w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-2048x835.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In this example, we focus on retrieving error emails that match specific conditions from Gmail and transferring their content to a Google Sheet.<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-60 wp-block-paragraph\">By setting criteria such as keywords in the subject line or body, as well as the retrieval period, the system reflects the email&#8217;s date, sender, subject, body, and extracted keywords in the spreadsheet.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Entering the Required Information in the Spreadsheet<\/h2>\n\n\n\n<figure class=\"wp-block-image size-large u-mb-ctrl u-mb-40\"><img decoding=\"async\" width=\"1024\" height=\"251\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-16-1024x251.png\" alt=\"\" class=\"wp-image-17048\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-16-1024x251.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-16-300x74.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-16-768x189.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-16-1536x377.png 1536w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-16-2048x503.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In the search criteria input area at the top (cells B1 to B4), enter the conditions for the emails you want to retrieve.<\/p>\n\n\n\n<figure class=\"wp-block-table u-mb-ctrl u-mb-50\"><table><thead style=\"--thead-color--bg:var(--color_pale03);--thead-color--txt:var(--swl-text_color--black)\"><tr><th colspan=\"2\"><strong><strong>Search Criteria Input Area at the Top (B1 to B4)<\/strong><\/strong><\/th><\/tr><\/thead><tbody><tr><td>Cell B1<\/td><td>Keyword included in the email subject (e.g., &#8220;Error&#8221;)<\/td><\/tr><tr><td>Cell B2<\/td><td>Keyword included in the email body (e.g., &#8220;Email delivery system&#8221;)<\/td><\/tr><tr><td>Cell B3<\/td><td>Start date for the emails to retrieve (emails within the specified date range will be extracted)<\/td><\/tr><tr><td>Cell B4<\/td><td>End date for the emails to fetch<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Next, enter the email fields to be fetched in columns A to E.<\/p>\n\n\n\n<figure class=\"wp-block-table u-mb-ctrl u-mb-50\"><table><thead style=\"--thead-color--bg:var(--color_pale03);--thead-color--txt:var(--swl-text_color--black)\"><tr><th colspan=\"2\">Columns A to E<\/th><\/tr><\/thead><tbody><tr><td>Column A<\/td><td>Email date<\/td><\/tr><tr><td>Column B<\/td><td>Sender&#8217;s email address<\/td><\/tr><tr><td>Column C<\/td><td>Email subject<\/td><\/tr><tr><td>Column D<\/td><td>Email body<\/td><\/tr><tr><td>Column E<\/td><td>Extracted keyword from the email body, if a keyword is included<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u691c\u7d22\u6761\u4ef6\u306e\u8a18\u5165\u4f8b<\/strong><\/p>\n\n\n<div class=\"wp-block-image u-mb-ctrl u-mb-40\">\n<figure class=\"alignleft size-full is-resized\"><img decoding=\"async\" width=\"707\" height=\"307\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-17.png\" alt=\"\" class=\"wp-image-17049\" style=\"width:424px;height:auto\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-17.png 707w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/image-17-300x130.png 300w\" sizes=\"(max-width: 707px) 100vw, 707px\" \/><\/figure>\n<\/div>\n\n\n<ul class=\"wp-block-list\">\n<li>Cell B1\uff1a&#8221;Error&#8221;<\/li>\n\n\n\n<li>B2\u30bb\u30eb\uff1a&#8221;Email delivery system&#8221;<\/li>\n\n\n\n<li>B3\u30bb\u30eb\uff1aStart date of the search period: &#8220;2024\/10\/04&#8221;<\/li>\n\n\n\n<li class=\"u-mb-ctrl u-mb-60\">B4\u30bb\u30eb\uff1aEnd date of the search period: &#8220;2024\/10\/10&#8221;<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Setting Up Google Apps Script<\/strong><\/h2>\n\n\n\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"function saveEmailsToSheet() {\n  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();\n\n  \/\/ Get the subject to search for from cell B1\n  const searchPhrase = sheet.getRange(&quot;B1&quot;).getValue();\n  if (!searchPhrase) {\n    Logger.log(&quot;The search phrase is empty.&quot;);\n    return; \/\/ Exit if B1 is empty\n  }\n\n  \/\/ Get the start and end dates for email retrieval from cells B3 and B4\n  const startDate = new Date(sheet.getRange(&quot;B3&quot;).getValue());\n  const endDate = new Date(sheet.getRange(&quot;B4&quot;).getValue());\n  if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {\n    Logger.log(&quot;Invalid start or end date.&quot;);\n    return; \/\/ Exit if the dates are invalid\n  }\n\n  \/\/ Get the keyword from cell B2\n  const keyword = sheet.getRange(&quot;B2&quot;).getValue();\n\n  \/\/ Create a search query using the subject, start date, and end date\n  const formattedStartDate = Utilities.formatDate(startDate, Session.getScriptTimeZone(), &quot;yyyy\/MM\/dd&quot;);\n  const formattedEndDate = Utilities.formatDate(endDate, Session.getScriptTimeZone(), &quot;yyyy\/MM\/dd&quot;);\n  const searchQuery = `subject:&quot;${searchPhrase}&quot; after:${formattedStartDate} before:${formattedEndDate}`;\n\n  \/\/ Search Gmail for email threads matching the query\n  const threads = GmailApp.search(searchQuery);\n\n  let row = 7; \/\/ Start writing data from row 7\n\n  threads.forEach(thread =&gt; {\n    const messages = thread.getMessages();\n    messages.forEach(message =&gt; {\n      const date = message.getDate();\n      const from = message.getFrom();\n      const subject = message.getSubject();\n      const body = message.getPlainBody();\n\n      \/\/ Check if the keyword is in the email body, and extract it if present\n      let keywordExtract = &quot;&quot;;\n      if (keyword &amp;&amp; body.includes(keyword)) {\n        keywordExtract = keyword; \/\/ Extract the keyword if it's found in the body\n      }\n\n      \/\/ Write data to the spreadsheet (starting from row 7)\n      sheet.getRange(row, 1).setValue(date);\n      sheet.getRange(row, 2).setValue(from);\n      sheet.getRange(row, 3).setValue(subject);\n      sheet.getRange(row, 4).setValue(body);\n      sheet.getRange(row, 5).setValue(keywordExtract); \/\/ Write the extracted keyword in column E\n\n      row++;\n    });\n  });\n}\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">function<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">saveEmailsToSheet<\/span><span style=\"color: #F8F8F2\">() {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> sheet <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> SpreadsheetApp.<\/span><span style=\"color: #A6E22E\">getActiveSpreadsheet<\/span><span style=\"color: #F8F8F2\">().<\/span><span style=\"color: #A6E22E\">getActiveSheet<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Get the subject to search for from cell B1<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> searchPhrase <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;B1&quot;<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">getValue<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (<\/span><span style=\"color: #F92672\">!<\/span><span style=\"color: #F8F8F2\">searchPhrase) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    Logger.<\/span><span style=\"color: #A6E22E\">log<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;The search phrase is empty.&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #F92672\">return<\/span><span style=\"color: #F8F8F2\">; <\/span><span style=\"color: #88846F\">\/\/ Exit if B1 is empty<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Get the start and end dates for email retrieval from cells B3 and B4<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> startDate <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #F92672\">new<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">Date<\/span><span style=\"color: #F8F8F2\">(sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;B3&quot;<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">getValue<\/span><span style=\"color: #F8F8F2\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> endDate <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #F92672\">new<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">Date<\/span><span style=\"color: #F8F8F2\">(sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;B4&quot;<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">getValue<\/span><span style=\"color: #F8F8F2\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (<\/span><span style=\"color: #A6E22E\">isNaN<\/span><span style=\"color: #F8F8F2\">(startDate.<\/span><span style=\"color: #A6E22E\">getTime<\/span><span style=\"color: #F8F8F2\">()) <\/span><span style=\"color: #F92672\">||<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">isNaN<\/span><span style=\"color: #F8F8F2\">(endDate.<\/span><span style=\"color: #A6E22E\">getTime<\/span><span style=\"color: #F8F8F2\">())) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    Logger.<\/span><span style=\"color: #A6E22E\">log<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;Invalid start or end date.&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #F92672\">return<\/span><span style=\"color: #F8F8F2\">; <\/span><span style=\"color: #88846F\">\/\/ Exit if the dates are invalid<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Get the keyword from cell B2<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> keyword <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;B2&quot;<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">getValue<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Create a search query using the subject, start date, and end date<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> formattedStartDate <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> Utilities.<\/span><span style=\"color: #A6E22E\">formatDate<\/span><span style=\"color: #F8F8F2\">(startDate, Session.<\/span><span style=\"color: #A6E22E\">getScriptTimeZone<\/span><span style=\"color: #F8F8F2\">(), <\/span><span style=\"color: #E6DB74\">&quot;yyyy\/MM\/dd&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> formattedEndDate <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> Utilities.<\/span><span style=\"color: #A6E22E\">formatDate<\/span><span style=\"color: #F8F8F2\">(endDate, Session.<\/span><span style=\"color: #A6E22E\">getScriptTimeZone<\/span><span style=\"color: #F8F8F2\">(), <\/span><span style=\"color: #E6DB74\">&quot;yyyy\/MM\/dd&quot;<\/span><span style=\"color: #F8F8F2\">);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> searchQuery <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #E6DB74\">`subject:&quot;<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #F8F8F2\">searchPhrase<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">&quot; after:<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #F8F8F2\">formattedStartDate<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\"> before:<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #F8F8F2\">formattedEndDate<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">`<\/span><span style=\"color: #F8F8F2\">;<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #88846F\">\/\/ Search Gmail for email threads matching the query<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> threads <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> GmailApp.<\/span><span style=\"color: #A6E22E\">search<\/span><span style=\"color: #F8F8F2\">(searchQuery);<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">let<\/span><span style=\"color: #F8F8F2\"> row <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #AE81FF\">7<\/span><span style=\"color: #F8F8F2\">; <\/span><span style=\"color: #88846F\">\/\/ Start writing data from row 7<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  threads.<\/span><span style=\"color: #A6E22E\">forEach<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #FD971F; font-style: italic\">thread<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #66D9EF; font-style: italic\">=&gt;<\/span><span style=\"color: #F8F8F2\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> messages <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> thread.<\/span><span style=\"color: #A6E22E\">getMessages<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    messages.<\/span><span style=\"color: #A6E22E\">forEach<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #FD971F; font-style: italic\">message<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #66D9EF; font-style: italic\">=&gt;<\/span><span style=\"color: #F8F8F2\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> date <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> message.<\/span><span style=\"color: #A6E22E\">getDate<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> from <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> message.<\/span><span style=\"color: #A6E22E\">getFrom<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> subject <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> message.<\/span><span style=\"color: #A6E22E\">getSubject<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> body <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> message.<\/span><span style=\"color: #A6E22E\">getPlainBody<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #88846F\">\/\/ Check if the keyword is in the email body, and extract it if present<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #66D9EF; font-style: italic\">let<\/span><span style=\"color: #F8F8F2\"> keywordExtract <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #E6DB74\">&quot;&quot;<\/span><span style=\"color: #F8F8F2\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (keyword <\/span><span style=\"color: #F92672\">&amp;&amp;<\/span><span style=\"color: #F8F8F2\"> body.<\/span><span style=\"color: #A6E22E\">includes<\/span><span style=\"color: #F8F8F2\">(keyword)) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">        keywordExtract <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> keyword; <\/span><span style=\"color: #88846F\">\/\/ Extract the keyword if it&#39;s found in the body<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      }<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      <\/span><span style=\"color: #88846F\">\/\/ Write data to the spreadsheet (starting from row 7)<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">1<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(date);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(from);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">3<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(subject);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">4<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(body);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">5<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(keywordExtract); <\/span><span style=\"color: #88846F\">\/\/ Write the extracted keyword in column E<\/span><\/span>\n<span class=\"line\"><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">      row<\/span><span style=\"color: #F92672\">++<\/span><span style=\"color: #F8F8F2\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    });<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  });<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<div class=\"swell-block-accordion u-mb-ctrl u-mb-50\">\n<details class=\"swell-block-accordion__item\" data-swl-acc=\"wrapper\"><summary class=\"swell-block-accordion__title\" data-swl-acc=\"header\"><span class=\"swell-block-accordion__label\">Script Explanation<\/span><span class=\"swell-block-accordion__icon c-switchIconBtn\" data-swl-acc=\"icon\" aria-hidden=\"true\" data-opened=\"false\"><i class=\"__icon--closed icon-caret-down\"><\/i><i class=\"__icon--opened icon-caret-up\"><\/i><\/span><\/summary><div class=\"swell-block-accordion__body\" data-swl-acc=\"body\">\n<dl class=\"swell-block-dl\">\n<dt class=\"swell-block-dl__dt\">Retrieve the Spreadsheet Sheet Object<\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> sheet <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> SpreadsheetApp.<\/span><span style=\"color: #A6E22E\">getActiveSpreadsheet<\/span><span style=\"color: #F8F8F2\">().<\/span><span style=\"color: #A6E22E\">getActiveSheet<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The script retrieves the sheet object from the currently active spreadsheet. Subsequent operations will be performed on this sheet.<\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\">Retrieve the Subject to Search<\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"const searchPhrase = sheet.getRange(&quot;B1&quot;).getValue();\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> searchPhrase <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;B1&quot;<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">getValue<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The script retrieves the subject (search phrase) entered in cell &#8220;B1&#8221; of the spreadsheet. If the cell is empty, the process is terminated by the following validation check.<br><br><\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Retrieve the Start and End Dates<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"const startDate = new Date(sheet.getRange(&quot;B3&quot;).getValue());\nconst endDate = new Date(sheet.getRange(&quot;B4&quot;).getValue());\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> startDate <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #F92672\">new<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">Date<\/span><span style=\"color: #F8F8F2\">(sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;B3&quot;<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">getValue<\/span><span style=\"color: #F8F8F2\">());<\/span><\/span>\n<span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> endDate <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #F92672\">new<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #A6E22E\">Date<\/span><span style=\"color: #F8F8F2\">(sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;B4&quot;<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">getValue<\/span><span style=\"color: #F8F8F2\">());<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The script retrieves the start date and end date for email searches from cells &#8220;B3&#8221; and &#8220;B4&#8221;, respectively. Emails within this period will be targeted. If either date is invalid, the script will terminate at this point.<\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Retrieve the Keyword in the Body<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"const keyword = sheet.getRange(&quot;B2&quot;).getValue();\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> keyword <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #E6DB74\">&quot;B2&quot;<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">getValue<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The script retrieves the keyword entered in cell &#8220;B2&#8221; of the spreadsheet and later checks whether this keyword is included in the email body.<\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Create the Search Query<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"const searchQuery = `subject:&quot;${searchPhrase}&quot; after:${formattedStartDate} before:${formattedEndDate}`;\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> searchQuery <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #E6DB74\">`subject:&quot;<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #F8F8F2\">searchPhrase<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">&quot; after:<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #F8F8F2\">formattedStartDate<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\"> before:<\/span><span style=\"color: #F92672\">${<\/span><span style=\"color: #F8F8F2\">formattedEndDate<\/span><span style=\"color: #F92672\">}<\/span><span style=\"color: #E6DB74\">`<\/span><span style=\"color: #F8F8F2\">;<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Using the retrieved search phrase, start date, and end date, the script creates a Gmail search query. The query is based on the &#8220;subject,&#8221; &#8220;start date,&#8221; and &#8220;end date&#8221; to find emails that meet the specified criteria.<\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\">Search Email Threads<\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"const threads = GmailApp.search(searchQuery);\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> threads <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> GmailApp.<\/span><span style=\"color: #A6E22E\">search<\/span><span style=\"color: #F8F8F2\">(searchQuery);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">Using the search query, the script searches Gmail for email threads (collections of emails in a conversational format) that match the specified criteria.<\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\">Retrieve Email Data and Write to the Spreadsheet<\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"threads.forEach(thread =&gt; {\n  const messages = thread.getMessages();\n  messages.forEach(message =&gt; {\n    const date = message.getDate();\n    const from = message.getFrom();\n    const subject = message.getSubject();\n    const body = message.getPlainBody();\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">threads.<\/span><span style=\"color: #A6E22E\">forEach<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #FD971F; font-style: italic\">thread<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #66D9EF; font-style: italic\">=&gt;<\/span><span style=\"color: #F8F8F2\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> messages <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> thread.<\/span><span style=\"color: #A6E22E\">getMessages<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  messages.<\/span><span style=\"color: #A6E22E\">forEach<\/span><span style=\"color: #F8F8F2\">(<\/span><span style=\"color: #FD971F; font-style: italic\">message<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #66D9EF; font-style: italic\">=&gt;<\/span><span style=\"color: #F8F8F2\"> {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> date <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> message.<\/span><span style=\"color: #A6E22E\">getDate<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> from <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> message.<\/span><span style=\"color: #A6E22E\">getFrom<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> subject <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> message.<\/span><span style=\"color: #A6E22E\">getSubject<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">    <\/span><span style=\"color: #66D9EF; font-style: italic\">const<\/span><span style=\"color: #F8F8F2\"> body <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> message.<\/span><span style=\"color: #A6E22E\">getPlainBody<\/span><span style=\"color: #F8F8F2\">();<\/span><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The script retrieves all email messages from each email thread and extracts the sent date, sender, subject, and body from each message. It then writes this data to the spreadsheet.<\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\">Keyword Verification and Extraction<\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"let keywordExtract = &quot;&quot;;\nif (keyword &amp;&amp; body.includes(keyword)) {\n  keywordExtract = keyword;\n}\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #66D9EF; font-style: italic\">let<\/span><span style=\"color: #F8F8F2\"> keywordExtract <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> <\/span><span style=\"color: #E6DB74\">&quot;&quot;<\/span><span style=\"color: #F8F8F2\">;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F92672\">if<\/span><span style=\"color: #F8F8F2\"> (keyword <\/span><span style=\"color: #F92672\">&amp;&amp;<\/span><span style=\"color: #F8F8F2\"> body.<\/span><span style=\"color: #A6E22E\">includes<\/span><span style=\"color: #F8F8F2\">(keyword)) {<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">  keywordExtract <\/span><span style=\"color: #F92672\">=<\/span><span style=\"color: #F8F8F2\"> keyword;<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">}<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The script checks whether the keyword is included in the email body. If the keyword is found, it extracts and records the keyword.<\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Writing Data to the Spreadsheet<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"sheet.getRange(row, 1).setValue(date);\nsheet.getRange(row, 2).setValue(from);\nsheet.getRange(row, 3).setValue(subject);\nsheet.getRange(row, 4).setValue(body);\nsheet.getRange(row, 5).setValue(keywordExtract);\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">1<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(date);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">2<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(from);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">3<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(subject);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">4<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(body);<\/span><\/span>\n<span class=\"line\"><span style=\"color: #F8F8F2\">sheet.<\/span><span style=\"color: #A6E22E\">getRange<\/span><span style=\"color: #F8F8F2\">(row, <\/span><span style=\"color: #AE81FF\">5<\/span><span style=\"color: #F8F8F2\">).<\/span><span style=\"color: #A6E22E\">setValue<\/span><span style=\"color: #F8F8F2\">(keywordExtract);<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The retrieved data is written row by row into the spreadsheet. The columns are populated sequentially with the &#8220;Date,&#8221; &#8220;Email Address,&#8221; &#8220;Subject,&#8221; &#8220;Body,&#8221; and &#8220;Keyword Extraction Result.&#8221;<\/p>\n<\/dd>\n\n\n\n<dt class=\"swell-block-dl__dt\"><strong>Prepare to Enter Data in the Next Row<\/strong><\/dt>\n\n\n\n<dd class=\"swell-block-dl__dd\">\n<div class=\"wp-block-kevinbatdorf-code-block-pro\" data-code-block-pro-font-family=\"Code-Pro-JetBrains-Mono\" style=\"font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)\"><span role=\"button\" tabindex=\"0\" data-code=\"row++;\n\" style=\"color:#F8F8F2;display:none\" aria-label=\"Copy\" class=\"code-block-pro-copy-button\"><svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" style=\"width:24px;height:24px\" fill=\"none\" viewBox=\"0 0 24 24\" stroke=\"currentColor\" stroke-width=\"2\"><path class=\"with-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-6 9l2 2 4-4\"><\/path><path class=\"without-check\" stroke-linecap=\"round\" stroke-linejoin=\"round\" d=\"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2\"><\/path><\/svg><\/span><pre class=\"shiki monokai\" style=\"background-color: #272822\" tabindex=\"0\"><code><span class=\"line\"><span style=\"color: #F8F8F2\">row<\/span><span style=\"color: #F92672\">++<\/span><span style=\"color: #F8F8F2\">;<\/span><\/span>\n<span class=\"line\"><\/span><\/code><\/pre><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">The script increments the row number after writing data to ensure the next email&#8217;s data is written to the subsequent row.<br><br><\/p>\n<\/dd>\n<\/dl>\n<\/div><\/details>\n<\/div>\n\n\n\n<p class=\"wp-block-paragraph\">This script transfers emails that match specific conditions in Gmail to a Google Sheet.<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-60 wp-block-paragraph\">By entering search criteria into the designated cells in the spreadsheet, the script retrieves information such as the subject, body, and sender details of emails that meet those conditions.<\/p>\n\n\n\n<div class=\"swell-block-step u-mb-ctrl u-mb-60\" data-num-style=\"circle\">\n<div class=\"swell-block-step__item\"><div class=\"swell-block-step__number u-bg-main\"><span class=\"__label\">STEP<\/span><\/div><div class=\"swell-block-step__title u-fz-l\">Open Apps Script Editor<\/div><div class=\"swell-block-step__body\"><div class=\"wp-block-image u-mb-ctrl u-mb-40\">\n<figure class=\"alignleft size-full is-resized\"><img decoding=\"async\" width=\"933\" height=\"591\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/98efceb7a335447039dff05eb8d70d3d.png\" alt=\"\" class=\"wp-image-16537\" style=\"width:447px;height:auto\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/98efceb7a335447039dff05eb8d70d3d.png 933w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/98efceb7a335447039dff05eb8d70d3d-300x190.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/98efceb7a335447039dff05eb8d70d3d-768x486.png 768w\" sizes=\"(max-width: 933px) 100vw, 933px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Open a Google Spreadsheet and click on \u201c<strong>Extensions<\/strong>\u201d in the menu, then \u201c<strong>Apps Script<\/strong>\u201d to open the Apps Script editor.<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"swell-block-step__item\"><div class=\"swell-block-step__number u-bg-main\"><span class=\"__label\">STEP<\/span><\/div><div class=\"swell-block-step__title u-fz-l\"><strong>Create the Script<\/strong><\/div><div class=\"swell-block-step__body\">\n<p class=\"wp-block-paragraph\">Copy the code above and paste it into the editor.<\/p>\n\n\n<div class=\"wp-block-image u-mb-ctrl u-mb-40\">\n<figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"1024\" height=\"472\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662-1024x472.png\" alt=\"\" class=\"wp-image-16191\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662-1024x472.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662-300x138.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662-768x354.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/e5e524d3405a7a1c3cfaaf3f2b1cc662.png 1387w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div><\/div><\/div>\n\n\n\n<div class=\"swell-block-step__item\"><div class=\"swell-block-step__number u-bg-main\"><span class=\"__label\">STEP<\/span><\/div><div class=\"swell-block-step__title u-fz-l\"><strong>Save the Script<\/strong><\/div><div class=\"swell-block-step__body\">\n<figure class=\"wp-block-image size-large u-mb-ctrl u-mb-40\"><img decoding=\"async\" width=\"1024\" height=\"359\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-1024x359.png\" alt=\"\" class=\"wp-image-17046\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-1024x359.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-300x105.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-768x269.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-1536x538.png 1536w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d.png 1708w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">After writing the script, name and save it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">(e.g., \u201cFetch Emails\u201d)<\/p>\n<\/div><\/div>\n\n\n\n<div class=\"swell-block-step__item\"><div class=\"swell-block-step__number u-bg-main\"><span class=\"__label\">STEP<\/span><\/div><div class=\"swell-block-step__title u-fz-l\"><strong>Run the Script<\/strong><\/div><div class=\"swell-block-step__body\"><div class=\"wp-block-image u-mb-ctrl u-mb-40\">\n<figure class=\"alignleft size-large\"><img decoding=\"async\" width=\"1024\" height=\"359\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-1-1024x359.png\" alt=\"\" class=\"wp-image-17047\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-1-1024x359.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-1-300x105.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-1-768x269.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-1-1536x538.png 1536w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/4daba083067bb083e64e0367460ecd8d-1.png 1708w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">Run the script to fetch emails that match the specified conditions.<\/p>\n<\/div><\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-group is-style-big_icon_memo u-mb-ctrl u-mb-60\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<p class=\"wp-block-paragraph\">If you&#8217;re running the script for the first time, you need to authorize it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Therefore, press &#8220;<strong>Review Permissions.<\/strong>&#8220;<\/strong><\/p>\n\n\n<div class=\"wp-block-image u-mb-ctrl u-mb-50\">\n<figure class=\"alignleft size-full\"><img decoding=\"async\" width=\"882\" height=\"345\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/image-79.png\" alt=\"\" class=\"wp-image-15938\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/image-79.png 882w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/image-79-300x117.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/image-79-768x300.png 768w\" sizes=\"(max-width: 882px) 100vw, 882px\" \/><\/figure>\n<\/div>\n\n\n<div class=\"swell-block-accordion\">\n<details class=\"swell-block-accordion__item\" data-swl-acc=\"wrapper\"><summary class=\"swell-block-accordion__title\" data-swl-acc=\"header\"><span class=\"swell-block-accordion__label\">Detailed Authorization Steps<\/span><span class=\"swell-block-accordion__icon c-switchIconBtn\" data-swl-acc=\"icon\" aria-hidden=\"true\" data-opened=\"false\"><i class=\"__icon--closed icon-caret-down\"><\/i><i class=\"__icon--opened icon-caret-up\"><\/i><\/span><\/summary><div class=\"swell-block-accordion__body\" data-swl-acc=\"body\">\n<p class=\"wp-block-paragraph\"><strong>Press &#8220;Advanced.&#8221;<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full u-mb-ctrl u-mb-50\"><img decoding=\"async\" width=\"1272\" height=\"688\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d.jpg\" alt=\"\" class=\"wp-image-15939\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d.jpg 1272w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d-300x162.jpg 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d-1024x554.jpg 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/188993dfac23ed4b35c326d75de2796d-768x415.jpg 768w\" sizes=\"(max-width: 1272px) 100vw, 1272px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Press &#8220;Go to Untitled project (Unsafe).&#8221;<\/strong><\/p>\n\n\n<div class=\"wp-block-image u-mb-ctrl u-mb-50\">\n<figure class=\"alignleft size-full\"><img decoding=\"async\" width=\"1305\" height=\"893\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9.jpg\" alt=\"\" class=\"wp-image-15940\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9.jpg 1305w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9-300x205.jpg 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9-1024x701.jpg 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/b7775751f92380510b389302eaafe1b9-768x526.jpg 768w\" sizes=\"(max-width: 1305px) 100vw, 1305px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\"><strong>After that, press &#8220;Allow.&#8221;<\/strong><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"alignleft size-full is-resized\"><img decoding=\"async\" width=\"955\" height=\"543\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/7ebb34b4d2c42fa532ad1c35c1ec1049.jpg\" alt=\"\" class=\"wp-image-15941\" style=\"width:566px;height:auto\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/7ebb34b4d2c42fa532ad1c35c1ec1049.jpg 955w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/7ebb34b4d2c42fa532ad1c35c1ec1049-300x171.jpg 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/11\/7ebb34b4d2c42fa532ad1c35c1ec1049-768x437.jpg 768w\" sizes=\"(max-width: 955px) 100vw, 955px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n<\/div><\/details>\n<\/div>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><strong><span class=\"swl-fz u-fz-l\">Gmail Fetch Results<\/span><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large u-mb-ctrl u-mb-40\"><img decoding=\"async\" width=\"1024\" height=\"417\" src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-1024x417.png\" alt=\"\" class=\"wp-image-17036\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-1024x417.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-300x122.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-768x313.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-1536x626.png 1536w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/2cfa90065dc54aae17f40c1f29e2ee41-2048x835.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">When the script is executed, the email data matching the specified conditions will be written to the spreadsheet starting from row 7.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Benefits of Using Google Apps Script<\/strong><\/h2>\n\n\n\n<div class=\"swell-block-capbox cap_box is-style-onborder_ttl2 u-mb-ctrl u-mb-30\" data-colset=\"col3\"><div class=\"cap_box_ttl\"><span><strong>Key Advantages<\/strong><\/span><\/div><div class=\"cap_box_content\">\n<ul class=\"wp-block-list\">\n<li><strong>Time-Saving<\/strong><br>Once the script is executed, email content is quickly transferred to the spreadsheet, reducing the time spent on manual tasks.<br><\/li>\n\n\n\n<li><strong>Prevention of Human Error<\/strong><br>Eliminates mistakes caused by manual copying and pasting.<br><\/li>\n\n\n\n<li><strong>Reusable After Initial Setup<\/strong><br>After setting up the script once, you can easily reuse it to transfer emails without any additional effort.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<p class=\"wp-block-paragraph\">When manually transferring error email content to a spreadsheet, you need to open each email, copy the content, and paste it into the spreadsheet every time.<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-60 wp-block-paragraph\">By using Google Apps Script, all these tasks are automated, significantly reducing the time required.<\/p>\n\n\n\n<h2 class=\"wp-block-heading u-mb-ctrl u-mb-40\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Manual data entry can be time-consuming, but automating the process with Google Apps Script saves time and allows you to focus on other tasks.<\/p>\n\n\n\n<p class=\"u-mb-ctrl u-mb-40 wp-block-paragraph\">Once the script is set up, transferring data to a spreadsheet becomes effortless. This makes it an excellent solution for anyone looking to streamline their workflow and improve efficiency.<\/p>\n\n\n<div class=\"p-postListWrap\"><ul class=\"p-postList -type-card -pc-col3 -sp-col1\"><li class=\"p-postList__item\">\n\t<a href=\"https:\/\/84office.jp\/en\/gas-pop-up\/\" class=\"p-postList__link\">\n\t\t<div class=\"p-postList__thumb c-postThumb\">\n\t<figure class=\"c-postThumb__figure\">\n\t\t<img decoding=\"async\" width=\"1024\" height=\"538\"  src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/f7db322d686e3090883637bf91b1d3ac-1024x538.png\" alt=\"\" class=\"c-postThumb__img u-obf-cover\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/f7db322d686e3090883637bf91b1d3ac-1024x538.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/f7db322d686e3090883637bf91b1d3ac-300x158.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/f7db322d686e3090883637bf91b1d3ac-768x403.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/f7db322d686e3090883637bf91b1d3ac.png 1200w\" sizes=\"auto, (min-width: 960px) 400px, 100vw\" loading=\"lazy\" >\t<\/figure>\n\t\t\t<span class=\"c-postThumb__cat icon-folder\" data-cat-id=\"12\">Google Sheets<\/span>\n\t<\/div>\n\t\t\t\t\t<div class=\"p-postList__body\">\n\t\t\t\t<h2 class=\"p-postList__title\">Enhance User Interaction with Google Apps Script: How to Add Confirmation Pop-Ups to Prevent Mistakes<\/h2>\t\t\t\t\t\t\t\t<div class=\"p-postList__meta\">\n\t\t\t\t\t<div class=\"p-postList__times c-postTimes u-thin\">\n\t<time class=\"c-postTimes__posted icon-posted\" datetime=\"2024-12-31\" aria-label=\"\u516c\u958b\u65e5\">2024\u5e7412\u670831\u65e5<\/time><\/div>\n\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t\t<\/a>\n<\/li>\n<li class=\"p-postList__item\">\n\t<a href=\"https:\/\/84office.jp\/en\/googlesheets-xlookup\/\" class=\"p-postList__link\">\n\t\t<div class=\"p-postList__thumb c-postThumb\">\n\t<figure class=\"c-postThumb__figure\">\n\t\t<img decoding=\"async\" width=\"1024\" height=\"538\"  src=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/a98b1120712ae2558c294773114e59b3-2-1024x538.png\" alt=\"\" class=\"c-postThumb__img u-obf-cover\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/a98b1120712ae2558c294773114e59b3-2-1024x538.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/a98b1120712ae2558c294773114e59b3-2-300x158.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/a98b1120712ae2558c294773114e59b3-2-768x403.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2025\/01\/a98b1120712ae2558c294773114e59b3-2.png 1200w\" sizes=\"auto, (min-width: 960px) 400px, 100vw\" loading=\"lazy\" >\t<\/figure>\n\t\t\t<span class=\"c-postThumb__cat icon-folder\" data-cat-id=\"12\">Google Sheets<\/span>\n\t<\/div>\n\t\t\t\t\t<div class=\"p-postList__body\">\n\t\t\t\t<h2 class=\"p-postList__title\">Master XLOOKUP: Simplify Data Search and Learn the Key Differences from VLOOKUP and HLOOKUP<\/h2>\t\t\t\t\t\t\t\t<div class=\"p-postList__meta\">\n\t\t\t\t\t<div class=\"p-postList__times c-postTimes u-thin\">\n\t<time class=\"c-postTimes__posted icon-posted\" datetime=\"2025-01-17\" aria-label=\"\u516c\u958b\u65e5\">2025\u5e741\u670817\u65e5<\/time><\/div>\n\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t\t<\/a>\n<\/li>\n<li class=\"p-postList__item\">\n\t<a href=\"https:\/\/84office.jp\/en\/googlesheets-map-linkage\/\" class=\"p-postList__link\">\n\t\t<div class=\"p-postList__thumb c-postThumb\">\n\t<figure class=\"c-postThumb__figure\">\n\t\t<img decoding=\"async\" width=\"1024\" height=\"538\"  src=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/c79a346b2ddab646e17282bf7501e204-1024x538.png\" alt=\"\" class=\"c-postThumb__img u-obf-cover\" srcset=\"https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/c79a346b2ddab646e17282bf7501e204-1024x538.png 1024w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/c79a346b2ddab646e17282bf7501e204-300x158.png 300w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/c79a346b2ddab646e17282bf7501e204-768x403.png 768w, https:\/\/84office.jp\/wp-content\/uploads\/2024\/12\/c79a346b2ddab646e17282bf7501e204.png 1200w\" sizes=\"auto, (min-width: 960px) 400px, 100vw\" loading=\"lazy\" >\t<\/figure>\n\t\t\t<span class=\"c-postThumb__cat icon-folder\" data-cat-id=\"12\">Google Sheets<\/span>\n\t<\/div>\n\t\t\t\t\t<div class=\"p-postList__body\">\n\t\t\t\t<h2 class=\"p-postList__title\">Google Sheets + Google Maps: Automatically Generate Map Links from Addresses<\/h2>\t\t\t\t\t\t\t\t<div class=\"p-postList__meta\">\n\t\t\t\t\t<div class=\"p-postList__times c-postTimes u-thin\">\n\t<time class=\"c-postTimes__posted icon-posted\" datetime=\"2024-12-03\" aria-label=\"\u516c\u958b\u65e5\">2024\u5e7412\u67083\u65e5<\/time><\/div>\n\t\t\t\t<\/div>\n\t\t\t<\/div>\n\t\t\t<\/a>\n<\/li>\n<\/ul><\/div>\n\n\n<p class=\"is-style-emboss_box has-swl-pale-02-background-color has-background wp-block-paragraph\">Our company offers support for improving work efficiency through the use of Google Apps Script. <br>If you need assistance with Google Apps Script customization or error resolution, please feel free to contact us. <br>We are fully committed to supporting your business improvements.<br><br><a href=\"https:\/\/84office.jp\/contact\/\">Contact us here<br><\/a><\/p>\n\n\n\n<script src=\"https:\/\/codoc.jp\/js\/cms.js\" data-css=\"rainbow\" data-usercode=\"pQLZofrBiA\" charset=\"UTF-8\" defer><\/script>\n <div id=\"codoc-entry-9lNr9PuMXQ\" class=\"codoc-entries\" data-without-body=\"1\" data-support-button-text=\"Support with a Tip\" data-support-message=\"We will keep offering tools and information to boost work efficiency. Your support helps us provide even better content.\"><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Do you find it time-consuming and tedious to manually transfer information received in Gmail to a Google Sheet [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":17050,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"swell_btn_cv_data":"","_locale":"en_US","_original_post":"https:\/\/84office.jp\/?p=15009","footnotes":""},"categories":[12],"tags":[],"class_list":["post-17045","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-12","en-US"],"_links":{"self":[{"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/posts\/17045","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/comments?post=17045"}],"version-history":[{"count":1,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/posts\/17045\/revisions"}],"predecessor-version":[{"id":17051,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/posts\/17045\/revisions\/17051"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/media\/17050"}],"wp:attachment":[{"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/media?parent=17045"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/categories?post=17045"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/84office.jp\/wp-json\/wp\/v2\/tags?post=17045"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}