This Node.js project leverages nodemailer, node-cron,and googleapis to create an automated email sender. It allows users to schedule emails for delivery using cron jobs and provides a straightforward setup.
-
Clone the repository:
git clone https://github.com/dhelafrank/Automatic-Email-Sender.git
-
Navigate to the project directory:
cd Automatic-Email-Sender
-
Install dependencies using npm or yarn:
npm install # or yarn install
-
Create a
.env
file in the project root and add the following information:CLIENT_ID=your_google_client_id CLIENT_SECRET=your_google_client_secret REFRESH_TOKEN=your_oauth_refresh_token USER_EMAIL=[email protected]
-
Linux or Unix users could setup the project by running the
setup.sh
file in the Project's root directory
To start the script, use the following command:
npm start
# or
yarn start
Note: Ensure compliance with applicable laws and regulations when sending emails. Respect recipients' privacy and adhere to ethical email practices. This script is intended for legitimate and consensual use only.
You can trigger immediate email sending by uncommenting the function call in /app.js
:
selectAndDeleteRandomMessage("[email protected]", "Email Subject");
To schedule emails, the cron job is set to run every day at midnight:
cron.schedule('0 0 * * *', () => {
selectAndDeleteRandomMessage("[email protected]", "Email Subject");
});
you can modify the schedule as you want
The selectAndDeleteRandomMessage
function, found in /app.js
, takes two arguments:
- Recipient Email Address
- Email Subject
Feel free to customize the function call with the desired recipient and subject.
Caution: Respect email recipients' consent and provide an option to unsubscribe from the mailing list.
For more details, refer to the Google Cloud Console for obtaining CLIENT_ID
and CLIENT_SECRET
and OAuth Playground for obtaining the REFRESH_TOKEN
.