A REST API for sending emails built with Express in Node.js.
- Send emails using a simple API
- Easy integration into your application
- Node.js and npm installed
- A MAILJET account with access to the API (free tier available)
- A MongoDB account (free tier available)
- Clone the repository:
git clone https://github.com/TiagoRibeiro25/Send-Email-REST-API
- Install dependencies:
npm install
- Set up environment variables in a
.env
file:
MAILJET_URL="https://api.mailjet.com/v3.1/send"
MAILJET_PUBLIC_KEY="YOUR MAILJET PUBLIC KEY"
MAILJET_SECRET_KEY="YOUR MAILJET SECRET KEY"
MAILJET_FROM_EMAIL="THE EMAIL YOU WANT TO SEND FROM"
API_ACCESS_TOKEN="A RANDOM STRING"
EMAIL_DB_URI="YOUR MONGODB URI"
PORT=3000
- Start the server in development mode (nodemon):
npm run dev
Make a GET request to the /api/version
endpoint:
curl -X GET http://localhost:3000/api/version
Make a GET request to the /api/status
endpoint:
curl -X GET http://localhost:3000/api/status
Make a POST request to the /api/v2/send
endpoint with the following:
- Headers:
authorization: YOUR API_ACCESS_TOKEN
- Body:
{
"From": "Source Name",
"To": [
{
"Name": "Destination Name",
"Email":"Destination Email"
}
],
"Subject": "Subject of the email",
"Text": "Text of the email",
}
(the To
field supports multiple objects in the array)
This application can be easily deployed to a hosting platform.
Contributions are welcome! Please open an issue or submit a pull request.