A back-end tool for sending instantaneous and automatic email, built in Nodejs (Express, MongoDB).
- Clone a repository to your computer:
git clone https://github.com/Quocanhtp/email-cron-job.git
- Enter folder:
cd email-cron-job
- Install dependencies:
npm install
- Account
Enter folder: cd API
, open the file sendMail.js
In line 21, replace the username
and <password>
with your MongoDB account informations:
const uri ="mongodb+srv://username:<password>@cluster0-oyxhr.mongodb.net/test?retryWrites=true&w=majority";
- Database
Sign in to your MongoDB Atlas account, create your database name: Email_Google
After that, create 2 collections name: Config
and Data
In the Config
collection, you can generate your informations, this includes your email account information, and a timer.
- Email field: your email
- Password field: your email password account
- Timer field: this string is used for schedule the time you want to send your email. For example, in the picture described above, the literal:
* * * * * *
means you want the server sends immediately your email. For more information, please visit the document of node-cron to schedule the time by yourself.
In the Data
collection, it is primitive that in this scenario, you must create your own list of person's email to which you want send.
- Subject field: The title of email
- Email field: the email you want to send your content to
- Content field: any text
- Status field:
unsend
- this is default
This is only for test purpose, in another version of this project, I will include the API insert email data via a data form from a client interface, in which you do not have to insert manually in the database.
-
Open Terminal, and type
npm start
-
When the server has already started, you need to use an API development tool to call the API
localhost:8000/sendEmail
. I recommend the Postman tool, you can download it from here. Once you have installed Postman, type the API address and then click the send button to call the API to send email.
I send email to myself, the result appears like this:
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.