0.0.3 • Published 8 years ago

simple-mail-sender-server v0.0.3

Weekly downloads
3
License
ISC
Repository
github
Last release
8 years ago

Simple Mail Sender Server

  1. Motivation
  2. Mail service provider
  3. How to install ?
  4. API
    1. Static properties
      1. ERRORS
    2. Constructor
    3. start()
    4. stop()
    5. sendMail()
  5. REST API
    1. Send mail
  6. Tests

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: sucess
  • 400: problem in the data being received by the server
  • 500: internal server error

Tests

The following will run all the tests:

$ npm run test

It will:

  • flow check the codebase
  • eslint check the codebase
  • Run the integration tests
0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago