Page MenuHomePhabricator

D4291.id14211.diff
No OneTemporary

D4291.id14211.diff

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<Transport> {
+ 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,

File Metadata

Mime Type
text/plain
Expires
Mon, Dec 2, 1:43 PM (19 h, 6 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2607722
Default Alt Text
D4291.id14211.diff (2 KB)

Event Timeline