{"id":3539,"date":"2022-09-27T08:03:35","date_gmt":"2022-09-27T03:03:35","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=3539"},"modified":"2022-09-27T08:16:59","modified_gmt":"2022-09-27T03:16:59","slug":"save-gmail-attachments-to-google-drive-automatically-using-google-apps-script","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/","title":{"rendered":"Save Gmail Attachments to Google Drive Automatically Using Google Apps Script"},"content":{"rendered":"\n<p>In this tutorial, I will teach you how to <strong>Save Gmail Attachments to Google Drive Automatically<\/strong> Using <strong>Google Apps Script<\/strong>. Basically, I will give you a small <strong>code snippet<\/strong> that you have to copy\/paste inside Google Apps Script editor to enable the transfer of Gmail Attachments (PDF &amp; Images) to Google Drive.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 1:- Open Google Apps Script Website<\/h2>\n\n\n\n<p>First of all, visit the <a href=\"https:\/\/script.google.com\/home\" target=\"_blank\" rel=\"noreferrer noopener\">script.google.com<\/a> URL and then click the &#8220;New Project&#8221; button to create a new project.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"504\" height=\"357\" src=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_7-27-55-AM.png\" alt=\"Google Apps Script - New Project\" class=\"wp-image-3541\" srcset=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_7-27-55-AM.png 504w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_7-27-55-AM-300x213.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><figcaption>Google Apps Script &#8211; New Project<\/figcaption><\/figure>\n\n\n\n<p>Within a few seconds, a new Google Apps Script project will be created for you.<\/p>\n\n\n\n<p>Here&#8217;s how the next screen will look.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"210\" src=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_7-31-35-AM-1024x210.png\" alt=\"Google Apps Script - Untitled Project\" class=\"wp-image-3542\" srcset=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_7-31-35-AM-1024x210.png 1024w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_7-31-35-AM-300x61.png 300w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_7-31-35-AM-768x157.png 768w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_7-31-35-AM.png 1366w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><figcaption>Google Apps Script &#8211; Untitled Project<\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Step 2:- Save Gmail Attachments to Google Drive Automatically<\/h2>\n\n\n\n<p>Here&#8217;s a source code that you just need to copy\/paste inside the <code>code.gs<\/code> file. This file is already opened in the Google Apps Script editor (as you can see in the above screenshot).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">code.gs<\/h3>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;javascript&quot;,&quot;mime&quot;:&quot;text\/javascript&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;styleActiveLine&quot;:true,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;JavaScript&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;js&quot;}\">const saveGmailtoGoogleDrive = () =&gt; {\n  const folderId = '1XsVZoyADqioGGMsFSuK27iqBSqbnaSY2';\n  const searchQuery = 'has:attachment';\n  const threads = GmailApp.search(searchQuery, 0, 10);\n  threads.forEach(thread =&gt; {\n    const messages = thread.getMessages();\n    messages.forEach(message =&gt; {\n      const attachments = message.getAttachments({\n          includeInlineImages: false,\n          includeAttachments: true\n      });\n      attachments.forEach(attachment =&gt; {\n        Drive.Files.insert(\n          {\n            title: attachment.getName(),\n            mimeType: attachment.getContentType(),\n            parents: [{ id: folderId }]\n          },\n          attachment.copyBlob()\n        );\n      });\n    });\n  });\n};<\/pre><\/div>\n\n\n\n<p><strong>Note:-<\/strong> Here you need to replace the value of <code>const folderId<\/code> with the <strong>ID<\/strong> of your own <strong>Google Drive<\/strong> folder.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Step 3:- Run the Script<\/h2>\n\n\n\n<p>Now, it&#8217;s time to execute this script by clicking the &#8220;Run&#8221; button given in the editor.<\/p>\n\n\n\n<p>After running the script, you will see that all the attachments inside your Gmail emails are automatically downloaded to Google Drive.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"961\" height=\"401\" src=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/gmail_emails_with_attachments.png\" alt=\"Gmail emails with attachments\" class=\"wp-image-3543\" srcset=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/gmail_emails_with_attachments.png 961w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/gmail_emails_with_attachments-300x125.png 300w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/gmail_emails_with_attachments-768x320.png 768w\" sizes=\"auto, (max-width: 961px) 100vw, 961px\" \/><figcaption>Gmail emails with attachments<\/figcaption><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Output Screenshot<\/h3>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"608\" height=\"492\" src=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_8-00-19-AM.png\" alt=\"Save Gmail Attachments to Google Drive Automatically\" class=\"wp-image-3544\" srcset=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_8-00-19-AM.png 608w, https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/scrnli_9_27_2022_8-00-19-AM-300x243.png 300w\" sizes=\"auto, (max-width: 608px) 100vw, 608px\" \/><figcaption>Save Gmail Attachments to Google Drive Automatically<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, I will teach you how to Save Gmail Attachments to Google Drive Automatically Using Google Apps Script. Basically, I will give you a small code snippet that you have to copy\/paste inside Google Apps Script editor to enable the transfer of Gmail Attachments (PDF &amp; Images) to Google Drive. Step 1:- Open &#8230; <a title=\"Save Gmail Attachments to Google Drive Automatically Using Google Apps Script\" class=\"read-more\" href=\"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/\" aria-label=\"Read more about Save Gmail Attachments to Google Drive Automatically Using Google Apps Script\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":3547,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-3539","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Save Gmail Attachments to Google Drive Automatically Using Google Apps Script<\/title>\n<meta name=\"description\" content=\"In this tutorial, I will teach you how to Save Gmail Attachments to Google Drive Automatically Using Google Apps Script. Basically, I will give you a\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Save Gmail Attachments to Google Drive Automatically Using Google Apps Script\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, I will teach you how to Save Gmail Attachments to Google Drive Automatically Using Google Apps Script. Basically, I will give you a\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-27T03:03:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-27T03:16:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/save_gmail_attachments_to_google_drive_automatically.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"880\" \/>\n\t<meta property=\"og:image:height\" content=\"495\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Save Gmail Attachments to Google Drive Automatically Using Google Apps Script","description":"In this tutorial, I will teach you how to Save Gmail Attachments to Google Drive Automatically Using Google Apps Script. Basically, I will give you a","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/","og_locale":"en_US","og_type":"article","og_title":"Save Gmail Attachments to Google Drive Automatically Using Google Apps Script","og_description":"In this tutorial, I will teach you how to Save Gmail Attachments to Google Drive Automatically Using Google Apps Script. Basically, I will give you a","og_url":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2022-09-27T03:03:35+00:00","article_modified_time":"2022-09-27T03:16:59+00:00","og_image":[{"width":880,"height":495,"url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/save_gmail_attachments_to_google_drive_automatically.jpg","type":"image\/jpeg"}],"author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"Save Gmail Attachments to Google Drive Automatically Using Google Apps Script","datePublished":"2022-09-27T03:03:35+00:00","dateModified":"2022-09-27T03:16:59+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/"},"wordCount":244,"commentCount":0,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/save_gmail_attachments_to_google_drive_automatically.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/","url":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/","name":"Save Gmail Attachments to Google Drive Automatically Using Google Apps Script","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/save_gmail_attachments_to_google_drive_automatically.jpg","datePublished":"2022-09-27T03:03:35+00:00","dateModified":"2022-09-27T03:16:59+00:00","description":"In this tutorial, I will teach you how to Save Gmail Attachments to Google Drive Automatically Using Google Apps Script. Basically, I will give you a","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/save_gmail_attachments_to_google_drive_automatically.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2022\/09\/save_gmail_attachments_to_google_drive_automatically.jpg","width":880,"height":495,"caption":"Save Gmail Attachments to Google Drive Automatically Using Google Apps Script"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/save-gmail-attachments-to-google-drive-automatically-using-google-apps-script\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Save Gmail Attachments to Google Drive Automatically Using Google Apps Script"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3539","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=3539"}],"version-history":[{"count":3,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3539\/revisions"}],"predecessor-version":[{"id":3546,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/3539\/revisions\/3546"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/3547"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=3539"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=3539"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=3539"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}