resilient-mailer-mailgun
implements Mailgun as an email provider for
resilient-mailer
.
var MailgunProvider = require('resilient-mailer-mailgun');
var mailgun = new MailgunProvider('example.com', 'key-MyApiKey');
var mailer; // ResilientMailer instance
mailer.registerProvider(mailgun);
$ npm install resilient-mailer-mailgun
Create an instance of the provider. There are also a number of options you can alter:
var MailgunProvider = require('resilient-mailer-mailgun');
var options = {
testMode: true, // see: http://documentation.mailgun.com/user_manual.html#sending-in-test-mode
apiSecure: false, // allows the use of HTTP rather than HTTPS
apiHostname: '127.0.0.1', // allows alternative hostname
apiPort: 8080 // allows unusual ports
};
var mailgun = new MailgunProvider('example.com', 'key-MyApiKey', options);
To register the provider with your ResilientMailer
instance:
var mailer; // ResilientMailer instance
mailer.registerProvider(mailgun);
In the event that you want to use MailgunProvider
directly (rather than the
usual way - via ResilientMailer
):
var message = {
from: 'no-reply@example.com',
to: ['user@example.net'],
subject: 'Testing my new email provider',
textBody: 'Seems to be working!',
htmlBody: '<p>Seems to be working!</p>'
};
mailgun.send(message, function (error) {
if (!error)
console.log('Success! The message sent successfully.');
else
console.log('Message sending failed - ' + error.message);
});
To see everything available in the message
object, refer to
resilient-mailer.
One instance of the provider covers one domain. To send from multiple domains,
you should set up multiple ResilientMailer
instances, with multiple matching
provider instances.
Install the development dependencies first:
$ npm install
Then the tests:
$ npm test
Please open an issue on this repository.
- James Billingham james@jamesbillingham.com
MIT licensed - see LICENSE file