More and more companies are sending electronic invoices.

  • Some do so by attachment,
  • others by embedding an URL to an on-line location.
    • For URLs, some require login or cookie, some don't.

I'm looking for a way to automate my Gmail so that for mails I (manually or automatically) mark with a certain label (like save-files or print-files) the files will be either saved, or printed.

Where should I get started?

I can put up a Windows VM behind firewall for this if needed.

Download probably suffices, as from there I should be able to print.

2 Answers 2


There's a nifty service called IFTTT (which stands for "If This Then That") that, among many other things, will allow you to create "Recipes" to automate certain tasks within certain "Channels".

Here's an example of an IFTTT recipe that saves "starred" Gmail attachments to an Evernote account. (Gmail and Evernote are just 2 of more than 160 "Channels" within IFTTT.)

And here's a recipe that adds Gmails labeled "To-do" to an iOS Reminders list.

  • 1
    IFTTT is awesome. I have a recipe that saves any PDF attachment where it finds "receipt" in the message body to my Google Drive.
    – ale
    Feb 1, 2015 at 0:07
  • @AlE. can you share that recipe? Feb 10, 2015 at 17:46
  • 1
    @Jeroen: Here's someone else's: Save electronic receipts to Gdrive. A quick search for "receipt" offers a bunch of other likely candidates.
    – ale
    Feb 10, 2015 at 19:30
  • Also, here's a link to the (currently) 775 recipes involving the terms "Gmail Google Drive": ifttt.com/connect/gmail/google_drive
    – Tom
    Feb 11, 2015 at 18:50
  • 1
    @JeroenWiertPluimers: Not mine, but this applet purports to do the same thing. Tweak as necessary.
    – ale
    Mar 15, 2017 at 15:27

This is not a programmatic/browser-only answer, as I believe any method that doesn't rely on ANY installed software could only be accomplished by building a Gmail add-on, a nontrivial task. But if you have Outlook for Desktop, you could set up a fairly simple Google Script to autoforward all threads under a certain label to a secondary email in your Outlook, then use the more powerful VBA scripting to extract/save attachments to local storage. Here's an example of the Google Script:

function autoForward() {
  var label = '<yourlabel>'; //replace "<yourlabel>" with the label of emails to target
  var recipient = '<[email protected]>'; //replace "<[email protected]>" with your destination email address
  var interval = 5;          //  if the script runs every 5 minutes; change otherwise
  var date = new Date();
  var timeFrom = Math.floor(date.valueOf()/1000) - 60 * interval;
  var threads = GmailApp.search('label:' + label) + ' after:' + timeFrom + 'has:attachment');
  for (var i = 0; i < threads.length; i++) {
    threads[i].getMessages()[0].forward(recipient);  // only the 1st message
    threads[i].markRead(); // mark each forwarded thread as read, one by one
    GmailApp.moveThreadsToTrash(threads); //change this to 

In Outlook for Desktop, set up your secondary email (you can even create a free Outlook.com email address then sync it via POP3 to Outlook for Desktop), then you have a lot more powerful tools like VBA macros. Then create a macro (may require adding the Developer tab to the toolbar, via Customize This Ribbon). Use this code to autosave attachments from emails:

Private Sub DownloadAttsFromSelection()
    Dim myNamespace As Outlook.NameSpace
    Set myNamespace = Application.GetNamespace("MAPI")
    Dim mi As MailItem
    Dim Atts As Attachments
    Dim Att As Attachment
    Dim strPath As String
    Dim strName As String
    For Each mi In myNamespace.GetDefaultFolder(6).Items
       Set Atts = mi.Attachments
       If Atts.Count > 0 Then
          For Each Att In Atts
            'Replace "test" with what you want to look for in attachment name
            If InStr(LCase(Att.FileName), "test") > 0 Then
              'Use your wanted destination folder path to save the attachments
              strPath = "C:\Attachments\"
              'Use your wanted destination folder path to save the attachments
              strName = NewMail.Subject & " " & Chr(45) & " " & Att.FileName
              Att.SaveAsFile strPath & strName
            End If
       End If
    Next mi
End Sub

Set this macro to run automatically (anytime your Outlook is open, at least) by going to Home > Rules > Manage Rules & Alerts > New Rule > Email Rules. In the popup, select "Apply rule on messages I receive". After clicking Next, check the box for "run a script" and select the VBA script you just created. Finish creating the rule.

ALTERNATIVELY, you could use a Google Script like gmail2gdrive (source code) to save attachments to a folder in your Google Drive, then use either Google Backup & Sync or Google Drive Desktop to sync it with a folder on your local drive.

  • Not using Outlook (I'm on multiple platforms so try to keep this all web based), but I like the gmail2gdrive suggestion. Need to give it quite a bit of thought. Is not going to happen soon given my situation (see profile). Oct 26, 2021 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.