From 4478f73a6ae1a3c0f417545542d415c0eea45e36 Mon Sep 17 00:00:00 2001 From: Eric Bolikowski Date: Thu, 23 Jan 2025 12:25:08 +0100 Subject: [PATCH] Feat/switch email sender provider (#1005) * feat(loopback): prototype send email via gworkspace * feat(nodejs): send via GWorkspace here too * switch sender for sweden emaisl --- apps/nestjs-api/src/email/lib/email/email.js | 49 ++++---------------- loopback-standalone/lib/email/email.js | 48 +++---------------- 2 files changed, 15 insertions(+), 82 deletions(-) diff --git a/apps/nestjs-api/src/email/lib/email/email.js b/apps/nestjs-api/src/email/lib/email/email.js index 73d9f2f01..6aeb1e221 100644 --- a/apps/nestjs-api/src/email/lib/email/email.js +++ b/apps/nestjs-api/src/email/lib/email/email.js @@ -2,29 +2,25 @@ import { buildFrontendUrl } from '../build-frontend-url' -const aws = require('aws-sdk') const Rx = require('rxjs') const mjml2html = require('mjml') const nodemailer = require('nodemailer') const fs = require('fs') const path = require('path') -const config = { - accessKeyId: process.env.NX_EMAILER_AWS_ACCESS_KEY, - secretAccessKey: process.env.NX_EMAILER_AWS_SECRET_KEY, - region: process.env.NX_EMAILER_AWS_REGION, -} - -const ses = new aws.SES(config) - const transporter = nodemailer.createTransport({ - SES: ses, + host: 'smtp.googlemail.com', + port: 465, + secure: true, + auth: { + user: 'career@redi-school.org', + pass: process.env.NX_GWORKSPACE_EMAIL_PASSWORD, + }, }) const isProductionOrDemonstration = () => ['production', 'demonstration', 'staging'].includes(process.env.NODE_ENV) -export const sendEmail = Rx.bindNodeCallback(ses.sendEmail.bind(ses)) export const sendMjmlEmail = Rx.bindNodeCallback( transporter.sendMail.bind(transporter) ) @@ -36,40 +32,11 @@ const getSenderDetails = (rediLocation) => { ? 'ReDI Malmö Team' : 'ReDI Talent Success Team' const senderEmail = isMalmoLocation - ? 'career.sweden@redi-school.org' + ? 'career@redi-school.org' // TODO: set back to career-sweden when we send email via Azure : 'career@redi-school.org' return { senderName, senderEmail } } -export const sendEmailFactory = (to, subject, body, rediLocation) => { - let toSanitized = isProductionOrDemonstration() ? to : '' - if (process.env.NX_DEV_MODE_EMAIL_RECIPIENT) { - toSanitized = process.env.NX_DEV_MODE_EMAIL_RECIPIENT - } - - const { senderName, senderEmail } = getSenderDetails(rediLocation) - - return sendEmail({ - Source: `${senderName} <${senderEmail}>`, - Destination: { - ToAddresses: [toSanitized], - BccAddresses: [`${senderName} <${senderEmail}>`], - }, - Message: { - Body: { - Text: { - Charset: 'UTF-8', - Data: body, - }, - }, - Subject: { - Charset: 'UTF-8', - Data: buildSubjectLine(subject, process.env.NODE_ENV), - }, - }, - }) -} - export const sendMjmlEmailFactory = ({ to, subject, html, rediLocation }) => { let toSanitized = isProductionOrDemonstration() ? to : '' if (process.env.NX_DEV_MODE_EMAIL_RECIPIENT) { diff --git a/loopback-standalone/lib/email/email.js b/loopback-standalone/lib/email/email.js index 1fbdbf273..fb792b2a8 100644 --- a/loopback-standalone/lib/email/email.js +++ b/loopback-standalone/lib/email/email.js @@ -1,31 +1,27 @@ 'use strict' -const aws = require('aws-sdk') const Rx = require('rxjs') const mjml2html = require('mjml') const nodemailer = require('nodemailer') const fs = require('fs') const path = require('path') -const config = { - accessKeyId: process.env.NX_EMAILER_AWS_ACCESS_KEY, - secretAccessKey: process.env.NX_EMAILER_AWS_SECRET_KEY, - region: process.env.NX_EMAILER_AWS_REGION, -} const { buildFrontendUrl } = require('../build-frontend-url') const { buildBackendUrl } = require('../build-backend-url') -const { ConsoleLogger } = require('@nestjs/common') - -const ses = new aws.SES(config) const transporter = nodemailer.createTransport({ - SES: ses, + host: 'smtp.googlemail.com', + port: 465, + secure: true, + auth: { + user: 'career@redi-school.org', + pass: process.env.NX_GWORKSPACE_EMAIL_PASSWORD, + }, }) const isProductionOrDemonstration = () => ['production', 'demonstration', 'staging'].includes(process.env.NODE_ENV) -const sendEmail = Rx.bindNodeCallback(ses.sendEmail.bind(ses)) const sendMjmlEmail = Rx.bindNodeCallback( transporter.sendMail.bind(transporter) ) @@ -42,35 +38,6 @@ const getSenderDetails = (rediLocation) => { return { senderName, senderEmail } } -const sendEmailFactory = (to, subject, body, rediLocation) => { - let toSanitized = isProductionOrDemonstration() ? to : '' - if (process.env.NX_DEV_MODE_EMAIL_RECIPIENT) { - toSanitized = process.env.NX_DEV_MODE_EMAIL_RECIPIENT - } - - const { senderName, senderEmail } = getSenderDetails(rediLocation) - - return sendEmail({ - Source: `${senderName} <${senderEmail}>`, - Destination: { - ToAddresses: [toSanitized], - BccAddresses: [`${senderName} <${senderEmail}>`], - }, - Message: { - Body: { - Text: { - Charset: 'UTF-8', - Data: body, - }, - }, - Subject: { - Charset: 'UTF-8', - Data: buildSubjectLine(subject, process.env.NODE_ENV), - }, - }, - }) -} - const sendMjmlEmailFactory = ({ to, subject, html, rediLocation }) => { let toSanitized = isProductionOrDemonstration() ? to : '' if (process.env.NX_DEV_MODE_EMAIL_RECIPIENT) { @@ -172,7 +139,6 @@ const sendConVerificationEmail = ({ module.exports = { sendResetPasswordEmail, - sendEmailFactory, sendMjmlEmailFactory, sendConVerificationEmail, }