-
+ |
Outline
diff --git a/server/emails/index.js b/server/emails/index.js
index 67d2c5f6..298941d5 100644
--- a/server/emails/index.js
+++ b/server/emails/index.js
@@ -15,11 +15,14 @@ router.get('/:type/:format', async ctx => {
};
switch (ctx.params.type) {
- case 'welcome':
- previewMailer.welcome('user@example.com');
- break;
+ // case 'emailWithProperties':
+ // previewMailer.emailWithProperties('user@example.com', {...properties});
+ // break;
default:
- throw httpErrors.NotFound();
+ if (Object.getOwnPropertyNames(previewMailer).includes(ctx.params.type)) {
+ // $FlowIssue flow doesn't like this but we're ok with it
+ previewMailer[ctx.params.type]('user@example.com');
+ } else throw httpErrors.NotFound();
}
if (!mailerOutput) return;
diff --git a/server/mailer.js b/server/mailer.js
index 910e7ea4..38569c81 100644
--- a/server/mailer.js
+++ b/server/mailer.js
@@ -2,7 +2,6 @@
import React from 'react';
import nodemailer from 'nodemailer';
import Oy from 'oy-vey';
-import invariant from 'invariant';
import { baseStyles } from './emails/components/EmailLayout';
import { WelcomeEmail, welcomeEmailText } from './emails/WelcomeEmail';
@@ -22,8 +21,8 @@ type SendMailType = {
*
* Mailer class to contruct and send emails.
*
- * To preview emails, add a new preview to `emails/index.js` and visit following
- * URLs in development mode:
+ * To preview emails, add a new preview to `emails/index.js` if they
+ * require additional data (properties). Otherwise preview will work automatically.
*
* HTML: http://localhost:3000/email/:email_type/html
* TEXT: http://localhost:3000/email/:email_type/text
@@ -35,16 +34,17 @@ class Mailer {
*
*/
sendMail = async (data: SendMailType): ?Promise<*> => {
- if (this.transporter) {
+ const { transporter } = this;
+
+ if (transporter) {
const html = Oy.renderTemplate(data.html, {
title: data.title,
headCSS: [baseStyles, data.headCSS].join(' '),
previewText: data.previewText,
});
- invariant(this.transporter, 'very sure this.transporter exists');
try {
- await this.transporter.sendMail({
+ await transporter.sendMail({
from: process.env.SMTP_SENDER_EMAIL,
to: data.to,
subject: data.title,
|