UNPKG

837 BJavaScriptView Raw
1"use strict";
2
3const EmailSender = require('./EmailSender');
4const AWS = require('aws-sdk');
5const callback = require('../helper/callback');
6
7/**
8 * Send email using AWS SES.
9 *
10 * Requires ```aws-sdk``` package.
11 */
12class SESEmailSender extends EmailSender
13{
14 constructor(region)
15 {
16 super();
17 AWS.config.update({
18 region
19 });
20 this.ses = new AWS.SES({
21 apiVersion: '2010-12-01'
22 });
23 }
24
25 sendImplementation(to, from, subject, body)
26 {
27 const packet = {
28 Source: from,
29 Destination: {
30 ToAddresses: [to]
31 },
32 Message: {
33 Subject: {
34 Data: subject
35 },
36 Body: {
37 Html: {
38 Data: body,
39 }
40 }
41 }
42 };
43
44
45 return callback(this.ses.sendEmail.bind(this.ses), packet);
46 }
47}
48
49module.exports = SESEmailSender;