Skip to content

TiagoRibeiro25/Send-Email-REST-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Send Email REST API

A REST API for sending emails built with Express in Node.js.

Features

  • Send emails using a simple API
  • Easy integration into your application

Prerequisites

  • Node.js and npm installed
  • A MAILJET account with access to the API (free tier available)
  • A MongoDB account (free tier available)

Getting Started

  1. Clone the repository:
git clone https://github.com/TiagoRibeiro25/Send-Email-REST-API
  1. Install dependencies:
npm install
  1. 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
  1. Start the server in development mode (nodemon):
npm run dev

Usage

Get API Current Version

Make a GET request to the /api/version endpoint:

curl -X GET http://localhost:3000/api/version

Get API Status

Make a GET request to the /api/status endpoint:

curl -X GET http://localhost:3000/api/status

Send an Email

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)

Deployment

This application can be easily deployed to a hosting platform.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.