doformify-mailer-service
Version:
Doformify Mailer
57 lines (52 loc) • 2.58 kB
JavaScript
;
const AWS = require('aws-sdk');
class Mailer {
constructor() {
AWS.config.update({region: process.env.ses_region});
this.ses = new AWS.SES({apiVersion: "dummyversion"});
}
sendTemplatedEmail(params) {
const locale = params.Locale || (() => {
throw new Error("The locale was missing while sending a new email.")
})();
return new Promise(async (resolve, reject) => {
this.ses.sendTemplatedEmail({
Source: params.Source,
Template: `${params.Template}_${locale}`,
Destination: {
ToAddresses: params.ToAddresses
},
TemplateData: params.TemplateData
}, function (err, data) {
if (err) reject(err);
else resolve(data);
});
});
}
}
module.exports = {
Mailer: new Mailer(),
WELCOME_EMAIL_TEMPLATE_NAME: "welcome-email",
USER_CONFIRMATION_EMAIL_TEMPLATE_NAME: "user-confirmation-email",
FIRST_SERVICE_CREATION_EMAIL_TEMPLATE_NAME: "first-service-creation-email",
ASSOCIATED_CHANNEL_EMAIL_TEMPLATE_NAME: "associated-channel-email",
SPAMMED_CONVERSATION_TEMPLATE_NAME: "spammed-conversation-email",
USER_ORDER_CREATION_PROVIDER_TEMPLATE_NAME: "user-order-creation-provider-email",
USER_ORDER_CREATION_USER_TEMPLATE_NAME: "user-order-creation-user-email",
USER_ORDER_NEW_STATUS_USER_TEMPLATE_NAME: "user-order-new-status-user-email",
USER_ORDER_NEW_STATUS_PROVIDER_TEMPLATE_NAME: "user-order-new-status-provider-email",
UPDATING_USER_EMAIL_TEMPLATE_NAME: "updating-user-email",
UPDATING_USER_PASSWORD_TEMPLATE_NAME: "updating-user-password-email",
PROVIDER_USER_REPORT_TEMPLATE_NAME: "provider-user-report-email",
PAYPAL_TRANSFER_CONFIRMATION_CODE: "paypal-transfer-confirmation-code-email",
PAYPAL_TRANSFER_IN_PLACE: "paypal-transfer-in-place-email",
PASSWORD_RECOVERY_EMAIL: "password-recovery-email",
AFTER_RESET_PASSWORD_EMAIL: "after-reset-password-email",
NEW_SESSION_UNRECOGNIZED_DEVICE_EMAIL: "new-session-unrecognized-device-email",
USER_ORDER_UPDATED_REQUIREMENTS: "user-order-updated-requirements-email",
NEW_USER_REQUEST_PROPOSAL: "new-user-request-proposal-email",
NEWSLETTERS_EMAIL_TEMPLATE_NAME: "newsletters-email",
UNSEEN_NOTIFICATION_EMAIL_TEMPLATE_NAME: "unseen-notification-email",
BLOCKED_REPORTED_USER_EMAIL_TEMPLATE_NAME: "blocked-reported-user-email",
PAUSE_SERVICE_EMAIL_TEMPLATE_NAME: "pause-service-email"
};