Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ PLATFORM_URI=https://some.domain
PLATFORM_LOGO=https://cdn.some.domain/some/path/to/some.img
NOTIFICATION_TO=developer@southcomm.com

SENDGRID_FROM=root@localhost
SENDGRID_API_KEY=some-api-key
EMAIL_FROM=root@localhost
MINDFUL_EMAIL_API_KEY=some-api-key

DEBUG=express:*
MONGOOSE_DEBUG=1
Expand All @@ -57,5 +57,6 @@ TENANT_KEY=
PLATFORM_URI=
PLATFORM_LOGO=
NOTIFICATION_TO=
SENDGRID_API_KEY=
EMAIL_FROM=
MINDFUL_EMAIL_API_KEY=
```
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ services:
AWS_SECRET_ACCESS_KEY: ${AWS_SECRET_ACCESS_KEY}
MONGO_DSN: ${MONGO_DSN-mongodb://mongo/cuf}
NOTIFICATION_TO: ${NOTIFICATION_TO-support@parameter1.com}
SENDGRID_API_KEY: ${SENDGRID_API_KEY}
SENDGRID_FROM: ${SENDGRID_FROM-no-reply@parameter1.com}
EMAIL_FROM: ${EMAIL_FROM-no-reply@parameter1.com}
MINDFUL_EMAIL_API_KEY: ${MINDFUL_EMAIL_API_KEY}
FETCH_TIMEOUT: ${FETCH_TIMEOUT-30000}
# Tenant-specific
BASE4_API_URL: ${BASE4_API_URL}
Expand Down
2 changes: 1 addition & 1 deletion services/graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
},
"dependencies": {
"@limit0/graphql-custom-types": "^1.0.1",
"@mindful-web/marko-web-mindful-email": "^1.60.0",
"@parameter1/base-cms-db": "^2.45.0",
"@sendgrid/mail": "^6.3.1",
"apollo-link-context": "^1.0.9",
"apollo-link-error": "^1.1.1",
"apollo-link-http": "^1.5.5",
Expand Down
3 changes: 1 addition & 2 deletions services/graphql/src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ module.exports = cleanEnv(process.env, {
AWS_S3_BUCKET: nonemptystr({ desc: 'The AWS S3 Bucket name to use for file uploads.', default: 'p1-cms-cuf-uploads' }),
MONGO_DSN: nonemptystr({ desc: 'The MongoDB DSN to connect to.', default: 'mongodb://mongo/cuf' }),
NOTIFICATION_TO: email({ desc: 'The email address notifications are sent to.' }),
SENDGRID_API_KEY: nonemptystr({ desc: 'The SendGrid API key for sending email.' }),
SENDGRID_FROM: nonemptystr({ desc: 'The from name to use when sending email via SendGrid, e.g. Foo <foo@bar.com>', default: 'no-reply@parameter1.com' }),
EMAIL_FROM: nonemptystr({ desc: 'The from name to use when sending email, e.g. Foo <foo@bar.com>', default: 'no-reply@parameter1.com' }),
// Tenant-specific settings
BASE4_API_URL: url({ desc: 'The management uri for the related platform tenant.' }),
GRAPHQL_URI: url({ desc: 'The URI to access the BaseCMS GraphQL instance' }),
Expand Down
35 changes: 14 additions & 21 deletions services/graphql/src/mailer.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,13 @@
const sgMail = require('@sendgrid/mail');
const sendMail = require('@mindful-web/marko-web-mindful-email');
const render = require('./templates');
const {
SENDGRID_API_KEY,
SENDGRID_FROM,
EMAIL_FROM,
NOTIFICATION_TO,
LOGO_URL,
CONTACT_URL,
CONTACT_TEXT,
} = require('./env');

const send = ({ to, subject, html }) => {
const payload = {
to,
from: SENDGRID_FROM,
subject,
html,
};

sgMail.setApiKey(SENDGRID_API_KEY);
const promise = sgMail.send(payload);
promise.catch((e) => { throw e; });
return promise;
};

const common = {
contactUrl: CONTACT_URL,
contactText: CONTACT_TEXT,
Expand All @@ -33,14 +18,22 @@ module.exports = {
async notify(submission = {}, { req }) {
const subject = 'A new company update requires review';
const html = await render('notify', { ...common, uri: `http://${req.get('host')}`, submission });
const to = NOTIFICATION_TO;
return send({ to, subject, html });
return sendMail({
to: NOTIFICATION_TO,
from: EMAIL_FROM,
subject,
html,
});
},
async thank(submission, { req }) {
const subject = 'Your requested updates have been received';
const html = await render('thankYou', { ...common, uri: `http://${req.get('host')}`, submission });
const { name, email } = submission;
const to = `${name} <${email}>`;
return send({ to, subject, html });
return sendMail({
to: `${name} <${email}>`,
from: EMAIL_FROM,
subject,
html,
});
},
};
Loading
Loading