/email-cron-job

A back-end tool for sending instantaneous and automatic email.

Primary LanguageJavaScriptMIT LicenseMIT

email-cron-job

A back-end tool for sending instantaneous and automatic email, built in Nodejs (Express, MongoDB).


Installation

  1. Clone a repository to your computer: git clone https://github.com/Quocanhtp/email-cron-job.git
  2. Enter folder: cd email-cron-job
  3. Install dependencies: npm install

Configuration

Setting MongoDB configuration

  1. 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";

  1. Database

Sign in to your MongoDB Atlas account, create your database name: Email_Google

After that, create 2 collections name: Config and Data

Capture

Config

In the Config collection, you can generate your informations, this includes your email account information, and a timer.

1

  • 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.

Data

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.

2

  • 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.

Running the project

  1. Open Terminal, and type npm start

  2. 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.

5

I send email to myself, the result appears like this:

4

3

Contributing

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.

License

MIT