diff --git a/keyserver/src/emails/sendmail.js b/keyserver/src/emails/sendmail.js --- a/keyserver/src/emails/sendmail.js +++ b/keyserver/src/emails/sendmail.js @@ -1,7 +1,12 @@ // @flow +import invariant from 'invariant'; import nodemailer from 'nodemailer'; +import { isDev } from 'lib/utils/dev-utils'; + +import { importJSON } from '../utils/import-json.js'; + type MailInfo = { +from: string, +to: string, @@ -14,6 +19,37 @@ ... }; -const sendmail: Transport = nodemailer.createTransport({ sendmail: true }); +type PostmarkConfig = { + +apiToken: string, +}; + +let cachedTransport: ?Transport; +async function getSendmail(): Promise { + if (cachedTransport) { + return cachedTransport; + } + const postmark: ?PostmarkConfig = await importJSON({ + folder: 'facts', + name: 'postmark', + }); + + if (isDev && !postmark) { + cachedTransport = nodemailer.createTransport({ sendmail: true }); + return cachedTransport; + } + + invariant(postmark, 'Postmark config missing'); + cachedTransport = nodemailer.createTransport({ + host: 'smtp.postmarkapp.com', + port: 587, + secure: false, + auth: { + user: postmark.apiToken, + pass: postmark.apiToken, + }, + requireTLS: true, + }); + return cachedTransport; +} -export default sendmail; +export default getSendmail; diff --git a/keyserver/src/emails/subscribe-email-updates.js b/keyserver/src/emails/subscribe-email-updates.js --- a/keyserver/src/emails/subscribe-email-updates.js +++ b/keyserver/src/emails/subscribe-email-updates.js @@ -6,7 +6,7 @@ import ashoat from 'lib/facts/ashoat'; import type { EmailSubscriptionRequest } from 'lib/types/account-types'; -import sendmail from './sendmail'; +import getSendmail from './sendmail'; import Template from './template.react'; async function sendEmailSubscriptionRequestToAshoat( @@ -22,8 +22,9 @@ ); const html = renderEmail(email); + const sendmail = await getSendmail(); await sendmail.sendMail({ - from: 'no-reply@squadcal.org', + from: 'no-reply@comm.app', to: ashoat.landing_email, subject: title, html,