This is a simple script that will automatically reply to emails that are sent to a specific email address. It is intended to be used with a Gmail account.
-
Go to Google Cloud Platform, enable the Gmail API, and create a new OAuth 2.0 Client ID. Download the client secret JSON file and save it as
credentials.jsonin the same directory as the script. -
Use
npm installto install the dependencies. -
Run the script using
npm startornode index. It will open a browser window and ask you to log in to your Google account. Then it will ask you to allow the script to access your Gmail account. Once you allow it, it will show a message saying that you can close the browser window. -
The script will create a file called
token.jsonin the same directory as the script. This file contains the OAuth 2.0 access token that the script uses to access your Gmail account. Keep this file in a safe place. If you lose it, you will have to repeat step 2. -
The script will constantly look for Unread emails in your Inbox (i.e. emails labelled as
INBOXandUNREAD) which are received after the script has been started. If it finds any, it will send an automatic reply to the sender of the email and adds the labelVacation Emailand removes the labelINBOX, and makes sure that the reply is sent only once.
- The script could be modified to not reply to emails that contain
noreplyorno-replyin the sender's email address.