An open API service indexing awesome lists of open source software.

https://github.com/trapcodeio/api2mailer-server

Api 2 Mailer Server
https://github.com/trapcodeio/api2mailer-server

Last synced: 3 months ago
JSON representation

Api 2 Mailer Server

Awesome Lists containing this project

README

        

# Api2Mailer

This package enables you to test remote `smtp/mailer` functionality from localhost without changing nodemailer's Api.

## What is included?

- A web server. (This Repo)
- An importable package. [api2mailer](https://npmjs.com/package/api2mailer)

### Web Server

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.

#### Hosting the server.

- clone this repo
- run `npm install` or `yarn install`
- run `node api2mailer cli @makeConfig` (Creates env.json)

Env.json Example:

```json
{
"port": 2222,
"transporters": {
"default": {
"host": "smtp.mailtrap.io",
"port": 2525,
"auth": {
"user": "",
"pass": ""
}
}
}
}
```

#### Start Server

```shell
node api2mailer
# OR using pm2
pm2 start api2mailer.js
```

This will start a server at `http://localhost:2222` or using your desired port.

### Sending Mail to Server

```js
// 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.