This package enables you to test remote smtp/mailer
functionality from localhost without changing nodemailer's Api.
- A web server. (This Repo)
- An importable package. api2mailer
This webserver should be hosted on the same server your main project is using.
It takes in nodemailer's sendMail
data via post request and sends the mail on the server.
- clone this repo
- run
npm install
oryarn install
- run
node api2mailer cli @makeConfig
(Creates env.json)
Env.json Example:
{
"port": 2222,
"transporters": {
"default": {
"host": "smtp.mailtrap.io",
"port": 2525,
"auth": {
"user": "",
"pass": ""
}
}
}
}
node api2mailer
# OR using pm2
pm2 start api2mailer.js
This will start a server at http://localhost:2222
or using your desired port.
// Example of how you send mail using `nodemailer`
const nodemailer = require('nodemailer')
const transporter = nodemailer.createTransport({/* Transporter Settings */})
await transporter.sendMail({/* Mail Options */});
// Example of how you send mail using `api2mailer`
const nodemailer = require('api2mailer')
const transporter = nodemailer.createTransport({/* Transporter Settings */})
await transporter.sendMail({/* Mail Options */});
The difference between both is: api2mailer
proxies your data to your api2mailer-server
endpoint which then sends
your mail on the remote server.