This project is a backend service designed to send emails via a RESTful API. Built with Node.js and Express, it leverages Nodemailer for handling email delivery. This service does not include a frontend; instead, it provides an endpoint for other applications to send emails programmatically.
- Backend: Node.js, Express
- Email: Nodemailer
- CORS: Middleware to handle cross-origin requests
- dotenv: For managing environment variables
-
Clone this repository:
git clone https://github.com/aldotobing/express-mail-service.git cd express-mail-service -
Install dependencies:
npm install
-
Create a .env file in the root directory and configure your SMTP settings:
SMTP_HOST=your_smtp_host SMTP_PORT=your_smtp_port SMTP_USER=your_smtp_user SMTP_PASS=your_smtp_password
-
Start the server:
node index.js
-
The service will be running on
http://localhost:3030
POST /send-emailSends an email using the details provided in the request body.
{
"name": "John Doe",
"email": "johndoe@example.com",
"subject": "Test Email",
"message": "Hello, this is a test email!",
"to": "recipient@example.com"
}name: The sender's nameemail: The sender's email addresssubject: The email subjectmessage: The email contentto: The recipient's email address (required)
You can run this service using Docker. Follow these steps:
# Build the image
docker build -t express-mail-service .There are two ways to run the container:
docker run -d \
-p 3030:3030 \
-e SMTP_HOST=smtp.gmail.com \
-e SMTP_PORT=587 \
-e SMTP_USER=your_email@gmail.com \
-e SMTP_PASS=your_app_password \
--name mail-service \
express-mail-service# Create a .env file with your settings first, then:
docker run -d \
-p 3030:3030 \
--env-file .env \
--name mail-service \
express-mail-service# Stop the container
docker stop mail-service
# Start the container
docker start mail-service
# Remove the container
docker rm mail-service
# View logs
docker logs mail-service
# View container status
docker psThe service will be accessible at http://localhost:3030 when running in Docker.
This project is licensed under the MIT License.
