Gmail Attachments Downloader is a node.js script that allows you to define rules in order to scrap your emails and download attachments so they can be uploaded to a specific folder on your Google Drive.
Clone the repository, then add a client_secret.json file in the root folder. It should have the following syntax, and can be created using the Google Developer Console :
{
"web": {
"client_id": "xxxxx.apps.googleusercontent.com",
"project_id": "xxxxx",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "xxxxx",
"redirect_uris": [
"http://localhost:3000/oauth2callback"
]
}
}
In the future, this part will be handled by a server of mine, so you don't have to worry about the app authentification.
Gmail Attachment Downloader needs to know some rules so it can behave the way you want it to behave. This is done by modifying src/userConfiguration.ts
.
It has to export as default an array of Rule
(see configuration.ts).
You can add new rules by creating new instances of the Rule
object :
new Rule({
//Required
name: 'The Lil Uzi Vert Rule',
sender: '[email protected]',
mimeType: 'application/pdf',
destination: '/rappers/uzi',
//Optional
unreadEmailsOnly: false,
markAsRead: true,
renameCallback: (originalFilename: string) => {
return `Uzi_${originalFilename}`;
},
}),
new Rule({ ... })
Here's a list of the properties the Rule
object can handle:
Property | Definition |
---|---|
name |
The name of the rule, useful for console displayed messages only |
sender |
The email of the sender it should look for |
mimeType |
The mimeType of the file it should look for |
destination |
The folder in which the new file will be placed. It has to be absolute, and the root is your My Drive folder |
Property | Default Value | Definition |
---|---|---|
unreadEmailsOnly |
true |
If true, it will only look for unread emails |
markAsRead |
false |
If true, it will mark as read every email that has been processed by the script |
renameCallback |
Returns the original file name | A function that takes the original file name (with its extension) and that returns and new file name that will be used in Google Drive |
Once you've done the setup, launch the following commands:
npm install
npm install -g typescript
tsc
node build/index.js
🍉