Skip to content

Instantly share code, notes, and snippets.

@m-torin
Forked from guikaercher/aws-ses.js
Created July 9, 2020 20:36
Show Gist options
  • Save m-torin/bd2bcb16d0bfb0687468894e410bac24 to your computer and use it in GitHub Desktop.
Save m-torin/bd2bcb16d0bfb0687468894e410bac24 to your computer and use it in GitHub Desktop.
AWS SES endpoints for TEMPLATES
const AWS = require('aws-sdk');
const ses = new AWS.SES({
region: 'us-east-1'
});
const createTemplate = () => {
var params = {
Template: { /* required */
TemplateName: 'teste_template', /* required */
HtmlPart: 'teste html',
SubjectPart: 'teste subject',
TextPart: 'teste text'
}
};
ses.createTemplate(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
const updateTemplate = () => {
var params = {
Template: { /* required */
TemplateName: 'teste_template', /* required */
HtmlPart: 'html atualizado',
SubjectPart: 'teste subject atualizado',
TextPart: 'teste text atualizado'
}
};
ses.updateTemplate(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
const getTemplate = () => {
var params = {
TemplateName: 'teste_template' /* required */
};
ses.getTemplate(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
const listTemplates = () => {
var params = {
MaxItems: 0,
// NextToken: ''
};
ses.listTemplates(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
}
const ReplacementTemplateData = {name: "Guilherme", favoriteanimal: "angelfish" }
const DefaultTemplateData = { name: "friend", favoriteanimal : "unknown" }
var params = {
Source:"[email protected]",
Template:"template_with_variables",
ConfigurationSetName: "",
Destinations:[
{
Destination:{
ToAddresses:[
"[email protected]"
]
},
ReplacementTemplateData: JSON.stringify(ReplacementTemplateData)
}
],
DefaultTemplateData: JSON.stringify(DefaultTemplateData)
}
ses.sendBulkTemplatedEmail(params, function(err, data) {
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment