Close

Simple Email Service(SES)

hazle.info

Install

// npm
npm install aws-sdk --save
// yarn
yarn add aws-sdk

Usage

aws.config.json

{
  "accessKeyId": "ACCESS_KEY_ID",
  "secretAccessKey": "SECRETACCESSKEY",
  "region": "REGION"
}

aws.ses.js

import Config from '~/path/to/aws.config.json'

const AWS = require('aws-sdk');
// AWS init
AWS.config.update({
  accessKeyId: Config.accessKeyId,
  secretAccessKey: Config.secretAccessKey,
  region: Config.region
});

// Module
export default function (ToAddresses, MessageSubject, MessageBody, FromAddresses) {
  let ses = new AWS.SES();

  // set Params Data
  params.Destination.ToAddresses = ToAddresses;
  params.Message.Subject.Data = MessageSubject;
  params.Message.Body.Html.Data = MessageBody;
  params.Source = FromAddresses;

  return ses.sendEmail(params, function (err) {
    if (err) {
      console.log(err)
    } else {
      console.log('SES Success')
    }
  })
}

// params template
let params = {
  Destination: {
    ToAddresses: [] // (array) To Addresses
  },
  Message: {
    Subject: {
      Data: '', // (string) Mail Title
      Charset: 'utf-8'
    },
    Body: {
      /*
      Text: {
        Data: '', // (string) Mail Content
        Charset: 'utf-8'
      }
      */
      Html: {
        Data: '', // (string) Mail Content
        Charset: 'utf-8'
      }
    }
  },
  Source: '' // (string) From Address
};

Leave a Reply

avatar
  Subscribe  
Notify of
%d 블로거가 이것을 좋아합니다: