sails-service-mailer
Service for Sails framework with Mailer features.
List of supported mail transports
- direct (sends email directly to MX server)
- SendGrid (SendGrid API)
- sendmail (sends email via sendmail)
- Amazon SES (sends email via Amazon SES services)
- SMTP (sends email via some of SMTP servers)
- Stub (stub sending of email)
Getting Started
Install this module.
npm install sails-service-mailer
Then require it in your service and create mailer instance.
// api/services/MailerService.js; 'sendmail' from: 'no-reply@my-project.com' subject: 'Hello, there' provider: path: '/usr/bin/sendmail' ; // api/controllers/MailController.js { MailerService ; };
Configuration
There is two kind of configuration - provider configuration and mail configuration.
When you instantiate new instance of mailer, in configuration object you can add provider
object.
This object will send directly to one of nodemailer transports.
And all keys that don't belongs to provider
will send directly to sendMail
function.
So basic configuration can be:
let mailer = ;
Each of available options you can find in nodemailer transport repositories or a little bit below in examples.
- Mail options you can find here.
- Provider options you can find in appropriate repository of nodemailer transports.
API
Each of Mailer instances has only one method:
send(config)
config
- Configuration object with mail options like from
, to
, etc... It will mix up to the pre-defined config.
All allowed options for this object you can find here.
Returns Promise.
Examples
All of this examples contains all the provider configuration keys. And most of them is optional.
DirectMailer
let direct = ;
SendGridMailer
let sendGrid = ;
SendMailMailer
let sendmail = ;
SESMailer
let ses = ;
SMTPMailer
let smtp = ;
StubMailer
let stub = ;
License
The MIT License (MIT)
Copyright (c) 2015 Eugene Obrezkov
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.