Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SendTemplatedEmail. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function sendEmail (context, options, callback) {
})
).then(response => {
if (response.statusCode >= 400) {
console.log(response.data)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use context.log

return Promise.reject(new Error('Amazon SES service returned status code: ' + response.statusCode))
}
return response
Expand All @@ -68,20 +69,24 @@ function sendEmail (context, options, callback) {

function encodeBody (context, options) {
context.log('validating params', options)
validateParams(options)
if (options.Template) {
validateTemplateParams(options)
} else {
validateParams(options)
}
context.log('params validated')

let body = encoder(Object.assign({}, options, { Action: 'SendEmail' }))
let body = encoder(Object.assign({}, options, {
Action: options.Template ? 'SendTemplatedEmail' : 'SendEmail'
}))
context.log('body encoded', body)
return body
}

const requiredEmailParams = ['Source', 'Destination', 'Message']

function validateParams (params) {
requiredEmailParams.forEach(prop =>
assert(params[prop], `The "${prop}" property is required`)
)
requiredEmailParams.forEach(prop => assert(params[prop], `The "${prop}" property is required`))
assert(params.Message.Body, 'The "Message.Body" property is required')
assert(params.Message.Subject, 'The "Message.Subject" property is required')
assert(params.Message.Subject.Data, 'The "Message.Subject.Data" property is required')
Expand All @@ -99,3 +104,8 @@ function validateParams (params) {
throw new Error('One of "Html", "Text" is required on Message.Body')
}
}

const requireTemplateParams = ['Source', 'Destination', 'Template', 'TemplateData']
function validateTemplateParams (params) {
requireTemplateParams.forEach(prop => assert(params[prop], `The "${prop}" property is required`))
}
Loading