altsendemail v0.2.1
altsendemail
A helper module to handle AWS SES.sendEmail.
Install
Install with npm:
$ npm install --save altsendemail
Usage
const {ParamsBuilder,SendEmail} = require('altsendemail');
const aws = require('aws-sdk');
const ses = new aws.SES({
accessKeyId: 'my-key',
secretAccessKey: 'my-secret',
region: 'my-region'
})
// #1. use when creating only params with ParamsBuilder
const paramsBuilder = new ParamsBuilder();
const params = paramsBuilder.from('foo@bar.baz')
.to([
'qux@qur.quz',
'rux@rur.ruz'
])
.subject('foo is bar')
.body('a story about foo.').params;
ses.sendEmail(params).promise()
.then(data=>{
console.log(data);
})
.catch(err=> {
console.log(err);
});
// #2. use when executing together with SendEmail
const sendEmail = new SendEmail(ses);
sendEmail.from('foo@bar.baz')
.to([
'qux@qur.quz',
'rux@rur.ruz'
])
.subject('foo is bar')
.body('a story about foo.')
.executeSendEmail()
.then(data=>{
console.log(data);
})
.catch(err=> {
console.log(err);
});
API Reference
class ParamsBuilder
constructor() ⇒ ParamsBuilder
to initiate an instance of the ParamsBuilder.
clear() ⇒ ParamsBuilder
to initialize all values of .params except .params.Source(from address).
from(addr) ⇒ ParamsBuilder
to set .params.Source by the addr argument.
to(addr or addr,...) ⇒ ParamsBuilder
to set .params.Destination.ToAddresses by the addr or array argument.
cc(addr or addr,...) ⇒ ParamsBuilder
to set .params.Destination.CcAddresses by the addr or array argument.
bcc(addr or addr,...) ⇒ ParamsBuilder
to set .params.Destination.BccAddresses by the addr or array argument.
replyTo(addr or addr,...) ⇒ ParamsBuilder
to set .params.ReplyToAddresses by the addr or array argument.
returnTo(addr) ⇒ ParamsBuilder
to set .params.ReturnPath by the addr argument.
returnPath(addr) ⇒ ParamsBuilder
to set .params.ReturnPath by the addr argument. It call returnTo(addr) internally.
subject(txt) ⇒ ParamsBuilder
to set .params.Message.Subject by the txt argument.
body(txt) ⇒ ParamsBuilder
to set .params.Message.Body by the txt argument.
class SendMessage extends ParamsBuilder
constructor(ses) ⇒ SendEmail
to initiate an instance of the SendEmail. A aws.SES instance is required.
executeSendEmail() ⇒ Promise
to execute the sendEmail method of the SES of the aws-sdk. It will return a Promise when called with no argument.
executeSendMessage(callback) ⇒ SendEmail
to execute the sendEmail method of the SES of the aws-sdk. It will return the SendEmail when called with a callback function.
License
Copyright © 2018, Seunghwan Noh. Released under the MIT License.