simple-mail-sender-server v0.0.3
Simple Mail Sender Server
Motivation
Having a very simple service that would send mails when contacted through HTTP requests.
Mail service provider
For the moment, I decided to go for Mailgun and it is free, easy to use and has a good reputation. The support for other mail service providers may come later.
How to install ?
npm install simple-mail-sender-server
API
First of all, you need to require the SMSS
class. simply do:
var SMSS = require('simple-mail-sender-server');
Static properties
ERRORS
Contains the error messages that can be thrown by instances of this class.
It currently contains:
NO_API_KEY
NO_DATA
NO_PORT_SPECIFIED
WRONG_ARGUMENTS
Constructor
var mySmss = new SMSS({
mailgun: {
apiKey: 'xxx', // You will get a SMSS.ERRORS.NO_API_KEY error if you don't provide this information
serverName: 'xxx' // This is optional. Please refer to the Mailgun driver documentation
}
});
start(options): Promise
Start the HTTP server.
options
is expected to be an object as follow:
host: 'localhost', // 'localhost' will be the default value if you don't specifiy this property
port: 1234 // The returned Promise will be rejected with a SMSS.ERRORS.NO_PORT_SPECIFIED error if you
// don't provide this information
The promise being returned is fullfilled when the server starts listening to new connections.
stop(): Promise
Stop the HTTP server.
The Promise being returned is fullfilled when the stop has stopped listening for incoming requests.
sendMail(sender, recipients, subject, text): Promise
Send a mail using your Mailgun API key.
sender
and recipients
are mandatory. subject
and text
aren't.
recipients
can be either a string or an array of strings
REST API
Send mail
POST /sendmail
{
"sender": "me@test.com",
"recipients": "them@test.com",
"subject": "alert",
"text": "Got the following error..."
}
Possible response:
200
: sucess400
: problem in the data being received by the server500
: internal server error
Tests
The following will run all the tests:
$ npm run test
It will: