Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
},
Source: 'noreply@tidepool.org', /* required */
Template: 'mcafee-template', /* required */
ConfigurationSetName: 'mcafee-email',
TemplateData: /* required */
'{ \"contactName\":\"' + CONTACT_PERSON +
'\", \"windowsLink\":\"' + downloadURL.windows +
'\", \"macOSLink\":\"' + downloadURL.macOS + '\"}',
ReplyToAddresses: [
'noreply@tidepool.org',
CONTACT_EMAIL,
],
};
// Create the promise and SES service object
const sendPromise = new aws.SES({apiVersion: '2010-12-01'})
.sendTemplatedEmail(params).promise();
sendPromise.then((data) => {
console.log('E-mail has been sent:', data);
}).catch((err) => {
console.error(err, err.stack);
});
}
console.log('Loading function');
// dependencies
var AWS = require('aws-sdk');
var crypto = require('crypto');
var config = require('./config.json');
// Get reference to AWS clients
var dynamodb = new AWS.DynamoDB();
var ses = new AWS.SES();
function getUser(email, fn) {
dynamodb.getItem({
TableName: config.DDB_TABLE,
Key: {
email: {
S: email
}
}
}, function(err, data) {
if (err) return fn(err);
else {
if ('Item' in data) {
fn(null, email);
} else {
fn(null, null); // User not found
// ABOUT THIS NODE.JS SAMPLE: This sample is part of the SDK for JavaScript Developer Guide topic at
// https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/ses-examples-managing-identities.html
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
// Set region
AWS.config.update({region: 'REGION'});
// Create listIdentities params
var params = {
IdentityType: "Domain",
MaxItems: 10
};
// Create the promise and SES service object
var listIDsPromise = new AWS.SES({apiVersion: '2010-12-01'}).listIdentities(params).promise();
// Handle promise's fulfilled/rejected states
listIDsPromise.then(
function(data) {
console.log(data.Identities);
}).catch(
function(err) {
console.error(err, err.stack);
});
var AWS = require('aws-sdk');
// Set the region
AWS.config.update({region: 'REGION'});
// Create updateTemplate parameters
var params = {
Template: {
TemplateName: 'TEMPLATE_NAME', /* required */
HtmlPart: 'HTML_CONTENT',
SubjectPart: 'SUBJECT_LINE',
TextPart: 'TEXT_CONTENT'
}
};
// Create the promise and SES service object
var templatePromise = new AWS.SES({apiVersion: '2010-12-01'}).updateTemplate(params).promise();
// Handle promise's fulfilled/rejected states
templatePromise.then(
function(data) {
console.log("Template Updated");
}).switch(
function(err) {
console.error(err, err.stack);
});
// snippet-end:[ses.JavaScript.templates.updateTemplate]
import * as AWS from 'aws-sdk';
import config from './config';
import logger from './logger';
AWS.config.update({
accessKeyId: config.aws.aws_access_key_id,
secretAccessKey: config.aws.aws_secret_access_key,
region: config.aws.aws_region
});
const ses = new AWS.SES();
export default (recipient: string, subject: string, text: string) => {
if (process.env.NODE_ENV === 'development' && !config.aws.aws_access_key_id && !config.aws.aws_secret_access_key) {
console.log(`Email not set up. Logging to console.\nTo: ${recipient}\nSubject: ${subject}\n${text}`);
} else {
ses.sendEmail({
Source: 'contact@metaspace2020.eu',
Destination: { ToAddresses: [recipient] },
Message: {
Subject: { Data: subject },
Body: { Text: { Data: text } },
},
}, (err, data) => {
if (err) logger.error(`Failed to sent email to ${recipient}: ${err}`);
else logger.info(`Sent email to ${recipient}`);
});
export async function sendEmail(params: ISESEmailParams): Promise {
if (process.env.APP_ENV !== 'production') {
params.Message.Subject.Data = 'QA: ' + params.Message.Subject.Data;
}
if (process.env.NODE_ENV === 'test') {
} else if (process.env.NODE_ENV === 'development') {
console.log('In develop mode, this email is not sent ', JSON.stringify(params));
} else {
if (params.Destination.ToAddresses.filter(item => item.includes('openelectionsportland.org')).length >= 1) {
console.log('Dont send emails to any address for openelectionsportland.org');
return params;
}
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY || !process.env.AWS_DEFAULT_REGION || !process.env.HOST_URL) {
throw new Error('The API needs AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY passed in as env variables');
}
const sendPromise = new AWS.SES({
apiVersion: '2010-12-01',
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
region: process.env.AWS_DEFAULT_REGION
}).sendEmail(params).promise();
await sendPromise.then(
(data) => {
console.log('sent email to ', params.Destination.ToAddresses, 'with aws ses message id of ', data.MessageId);
}).catch(error => console.log(error));
}
return Promise.resolve(params);
}
return new Promise((resolve, reject) => {
console.log("Email to " + options.to + " subject:" + subject);
if (this.sesRegion && this.sesRegion !== "") {
AWS.config.update({region: this.sesRegion});
let ses = new AWS.SES();
let mail = new MailComposer(options);
mail.compile().build((err, messageSource) => {
if (err) {
reject(err);
} else {
ses.sendRawEmail({RawMessage: {Data: messageSource}}, (err, data) => {
AWS.config.update({region: process.env.AWS_REGION});
if (err) {
reject(err, err.stack);
} else {
resolve(data);
}
});
}
});
} else {
cb('Invalid Primary Email: ' + eachEmail);
}
});
ccEmailArray.forEach(function (eachEmail) {
if (!validateEmail(eachEmail)) {
cb('Invalid Cc Email: ' + eachEmail);
}
});
bccEmailArray.forEach(function (eachEmail) {
if (!validateEmail(eachEmail)) {
cb('Invalid Bcc Email: ' + eachEmail);
}
});
aws.config.region = 'us-west-2';
var transporter = nodemailer.createTransport({
SES: new aws.SES({
apiVersion: '2010-12-01'
})
});
var report, csvArray = [], supplier, emailSubject, totalOrderQuantity = 0, totalSupplyCost = 0, htmlForPdf, csvReport;
ReportModel.findById(id, {
include: ['userModel', 'storeConfigModel']
})
.then(function (reportModelInstance) {
report = reportModelInstance;
logger.debug({log: {message: 'Found this report model', report: reportModelInstance}});
if (reportModelInstance.supplier) {
logger.debug({log: {message: 'Will look for supplier for the report'}});
return ReportModel.app.models.SupplierModel.find({
where: {
api_id: reportModelInstance.supplier.id
}
var ses = new (require('aws-sdk').SES)();
////////////////////////////////////////////////////////////////////////////////
exports.handler = function(e, ctx) {
var params = prepareParams(e);
log('Received event:'); log(params);
if (!params) {
return ctx.done('Invalid params provided. Finished with error.');
}
ses.sendEmail(params, function(err, data) {
if (err) {
log('SES error:'); log(err);
ctx.done('Finished with error.');
},
debug: !!configItems.smtpLog,
logger: !configItems.smtpLog ? false : {
debug: logfunc.bind(null, 'verbose'),
info: logfunc.bind(null, 'info'),
error: logfunc.bind(null, 'error')
},
maxConnections: Number(configItems.smtpMaxConnections),
maxMessages: Number(configItems.smtpMaxMessages),
tls: {
rejectUnauthorized: !configItems.smtpSelfSigned
}
};
} else if (configItems.mailTransport === 'ses') {
transportOptions = {
SES: new aws.SES({
apiVersion: '2010-12-01',
accessKeyId: configItems.sesKey,
secretAccessKey: configItems.sesSecret,
region: configItems.sesRegion
}),
debug: !!configItems.smtpLog,
logger: !configItems.smtpLog ? false : {
debug: logfunc.bind(null, 'verbose'),
info: logfunc.bind(null, 'info'),
error: logfunc.bind(null, 'error')
},
maxConnections: Number(configItems.smtpMaxConnections),
sendingRate,
tls: {
rejectUnauthorized: !configItems.smtpSelfSigned
}