as-email-sender
v1.1.6
Published
A simple and reusable email sender with multiple email service providers.
Downloads
3
Readme
as-email-sender
A simple and reusable email sender with multiple email service providers.
Feature
- Support 2 email providers
- Allow auto failover to other specified providers if needed
Installation
npm install as-email-sender
Configuration for Amazon SES
Create a credentials file at ~/.aws/credentials on Mac/Linux or C:\Users\USERNAME.aws\credentials on Windows
[default]
aws_access_key_id = your_access_key
aws_secret_access_key = your_secret_key
Create Amazon SES Client
var asEmailSender = require('as-email-sender');
var sesClient = asEmailSender.createSesClient();
Create Mailgun Client
var asEmailSender = require('as-email-sender');
var mailgunCredential = {
"apiKey": "xxxxxxxxx",
"domain": "yyyyyyyy.mailgun.org"
}
asEmailSender.createMailgunClient(mailgunCredentials);
Example code
var asEmailSender = require('as-email-sender');
// create two clients (providers) for auto failover
var clients = [
asEmailSender.createMailgunClient(mailgunCredentials),
asEmailSender.createSesClient()
]
var sender = new asEmailSender.Sender(clients, '[email protected]');
var params = sender.createBaseParams();
params.toAddresses = ['[email protected]'];
params.body = 'test';
params.subject = 'foo subject';
sender.sendEmail(params)
.then(function(result) {
console.log(result);
})
.catch(function(e) {
console.log(e);
});
Auto failover
The clients will be used in the order you have defined in the clients array.
When one client failed to send, the sending request will be retried by the subsequent client.
If all clients failed, a rejected promise will be returned.