Download All Inbox Attachments
This is a step by step coding guide for downloading all of the attachments in a Mailsac email inbox.
Choose a folder to work in, and navigate to the folder in your terminal.
Configure the npm package.json:
npm init -y npm install --save request request-promise-native
Create a file:
Now open the .js file and put the following code in. Change the string value of MAILSAC_API_KEY from ‘YOUR API KEY GOES HERE’ to your actual API key.
The script can be run in the terminal like this:
node download-inbox-attachments.js email@example.com
This Node script does a few things:
- Takes takes the email address ‘firstname.lastname@example.org’ as an input argument. You can change this to any email address.
- It fetches the metadata for all messages in the inbox email@example.com.
- It loops through the list of messages and prints part of the subject, the unique message identifier, and how many attachments it has.
- When messages have attachments, the attachment is downloaded into the current folder, using it’s MD5 checksum as an identifier.
That’s it! Read more about message attachment APIs in the docs.