-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
1 parent
1d58eeb
commit 4478f73
Showing
2 changed files
with
15 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: '[email protected]', | ||
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' | ||
? '[email protected]' // TODO: set back to career-sweden when we send email via Azure | ||
: '[email protected]' | ||
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) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: '[email protected]', | ||
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, | ||
} |