@samepage/backend
Version:
Backend utilities for the apis of SamePage integrations
43 lines • 1.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.supportEmail = void 0;
const tslib_1 = require("tslib");
const client_ses_1 = require("@aws-sdk/client-ses");
const server_1 = tslib_1.__importDefault(require("react-dom/server"));
const mockEmailLocally_server_1 = tslib_1.__importDefault(require("./mockEmailLocally.server"));
const ses = new client_ses_1.SES({
endpoint: process.env.AWS_ENDPOINT,
});
exports.supportEmail = "support@samepage.network";
const sendEmail = async ({ to = exports.supportEmail, body, subject, from = exports.supportEmail, replyTo, }) => {
const Data = typeof body === "string" ? body : server_1.default.renderToStaticMarkup(body);
const Body = {
Html: {
Charset: "UTF-8",
Data,
},
};
// custom ses client above should already be doing this, but is failing
if (process.env.NODE_ENV === "development") {
const MessageId = (0, mockEmailLocally_server_1.default)(Body);
return MessageId;
}
return ses
.sendEmail({
Destination: {
ToAddresses: typeof to === "string" ? [to] : to,
},
Message: {
Body,
Subject: {
Charset: "UTF-8",
Data: subject,
},
},
Source: from,
ReplyToAddresses: typeof replyTo === "string" ? [replyTo] : replyTo,
})
.then((r) => r.MessageId || "");
};
exports.default = sendEmail;
//# sourceMappingURL=sendEmail.server.js.map