How to do the unthinkable-automatically open hyperlinks in gmail message
January 12, 2021 11:41 PM   Subscribe

I use gmail. I frequently receive one particular type of email from a very trusted source that contains links to download documents. I’d like to automate retrieving and saving these documents.

I wish these emails would just send the documents to me as attachments, but alas, they do not. They only send me a link to go retrieve the document instead. But the link expires after an amount of time. If I forget to manually click the link and save the document, I sometimes find that I can no longer obtain the document at all because the link has expired before I remember to open the email again. Is there any way to set up a rule for this one trusted message sender that will automatically retrieve hyperlinked documents from the body of the message and then save it to my hard drive or google drive? Thanks for teaching me how to automate risky procedures!
posted by DB Cooper to Computers & Internet (3 answers total) 1 user marked this as a favorite
 
Best answer: I've just been having a poke around in Google Apps Script, a facility I've never used before.

There doesn't seem to be a way to trigger script execution on receipt of an email, but it is possible to make a script run periodically. So the path I'd be inclined to explore first would go something like this:

1. Create a couple of labels in your Gmail account called downloads-pending and downloads-complete.

2. Create a filter rule in your Gmail account that matches emails you trust to contain links that are safe to download, and have it add the downloads-pending label to all matching mails as they arrive.

3. Create a script function in Google Apps Script that searches your Gmail for mails with a downloads-pending label, scrapes them for download links, fetches the link targets and saves them in your Google Drive, then removes the downloads-pending label and adds a downloads-complete label.

4. Create a time based trigger that runs the above script every 15 minutes.

Post back if you hit roadblocks you can't get past by reading Google's documentation and doing searches for Google Apps Script snippets that look like they could be tweaked to suit your purpose.
posted by flabdablet at 4:38 AM on January 13, 2021


Response by poster: Thank you. I didn’t know this existed and it gives me a reason to learn javascript!
posted by DB Cooper at 10:57 PM on January 14, 2021 [1 favorite]


I didn't either until you asked this question, so thanks to you as well!
posted by flabdablet at 5:35 AM on January 15, 2021 [1 favorite]


« Older How to Pour a Helicopter Bucket of Water on Bursts...   |   Copper Heating Element Safety in Water Urn Newer »
This thread is closed to new comments.