Skip to content

Commit

Permalink
set email from name, add preview text
Browse files Browse the repository at this point in the history
  • Loading branch information
finlay-jisc committed Nov 3, 2023
1 parent b1b696a commit 503ce0b
Showing 1 changed file with 62 additions and 16 deletions.
78 changes: 62 additions & 16 deletions api/src/lib/email.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import SMTPTransport from 'nodemailer/lib/smtp-transport';
import * as aws from '@aws-sdk/client-ses';
import * as I from 'interface';

const from = process.env.EMAIL_SENDER_ADDRESS;
const from = {
name: 'Octopus.ac',
address: process.env.EMAIL_SENDER_ADDRESS || ''
};
const baseURL = process.env.BASE_URL;

const ses = new aws.SES({
Expand Down Expand Up @@ -122,7 +125,7 @@ const styles = {
`
};

export const standardHTMLEmailTemplate = (subject: string, html: string): string => {
export const standardHTMLEmailTemplate = (subject: string, html: string, previewText = ''): string => {
return `
<!DOCTYPE html>
<html lang="en">
Expand All @@ -133,6 +136,9 @@ export const standardHTMLEmailTemplate = (subject: string, html: string): string
<title>${subject}</title>
</head>
<body style="${styles.body}">
<div style="display: none; max-height: 0px; overflow: hidden;">${previewText}</div>
<!-- Separate preview text from rest of body with whitespace -->
<div style="display: none; max-height: 0px; overflow: hidden;">&#847; &zwnj; &nbsp; &#8199; &shy; &#847; &zwnj; &nbsp; &#8199; &shy; &#847; &zwnj; &nbsp; &#8199; &shy; &#847; &zwnj; &nbsp; &#8199; &shy; &#847; &zwnj; &nbsp; &#8199; &shy; &#847; &zwnj; &nbsp; &#8199; &shy; &#847; &zwnj; &nbsp; &#8199; &shy; &#847; &zwnj; &nbsp; &#8199; &shy;</div>
<div style="${styles.wrapper}">
<div style="${styles.header}">
<img
Expand Down Expand Up @@ -231,7 +237,11 @@ export const notifyCoAuthor = async (options: NotifyCoAuthor): Promise<void> =>
const text = `${options.userFirstName} ${options.userLastName} has added you as an author of the following publication on Octopus: ${options.publicationTitle}. To confirm your involvement, and see a preview of the publication, you can use this link: ${baseURL}/author-link?email=${options.coAuthor}&code=${options.code}&publicationId=${options.publicationId}&versionId=${options.versionId}&approve=true . If you are not an author of this publication, you can use this link: ${baseURL}/author-link?email=${options.coAuthor}&code=${options.code}&publicationId=${options.publicationId}&versionId=${options.versionId}&approve=false . An Octopus user has provided this email address so that you can receive this message. If you select that you are not involved with the publication named above, your data will be deleted immediately.`;

await send({
html: standardHTMLEmailTemplate('You’ve been added as a co-author on Octopus', html),
html: standardHTMLEmailTemplate(
'You’ve been added as a co-author on Octopus',
html,
'Next, confirm your involvement, and log in to get started'
),
text,
to: options.coAuthor,
subject: 'You’ve been added as a co-author on Octopus'
Expand Down Expand Up @@ -267,7 +277,7 @@ export const verificationCode = async (options: VerificationCode): Promise<void>
const text = `Please enter the following code to verify your email address: ${options.code}`;

await send({
html: standardHTMLEmailTemplate('Verify your Octopus account', html),
html: standardHTMLEmailTemplate('Verify your Octopus account', html, 'Use the code within to get started'),
text,
to: options.to,
subject: 'Verify your Octopus account'
Expand Down Expand Up @@ -308,7 +318,11 @@ export const newRedFlagAuthorNotification = async (
const text = `Your publication '${options.publicationName}' has been red flagged by ${options.submitter}. Flag type: ${options.type}. Flag message: ${options.flagReason}.`;

return send({
html: standardHTMLEmailTemplate('Your publication has been red flagged', html),
html: standardHTMLEmailTemplate(
'Your publication has been red flagged',
html,
'Somebody has identified a potential concern'
),
text,
to: options.to,
subject: 'Your publication has been red flagged'
Expand Down Expand Up @@ -340,7 +354,7 @@ export const newRedFlagCreatorNotification = async (
const text = `You have successfully red flagged this publication. You can view it here: ${baseURL}/publications/${options.publicationId}/flag/${options.flagId}`;

return send({
html: standardHTMLEmailTemplate('Red flag created', html),
html: standardHTMLEmailTemplate('Red flag created', html, "The publication's author has been notified"),
text,
to: options.to,
subject: 'Red flag created'
Expand Down Expand Up @@ -380,7 +394,7 @@ export const updateRedFlagNotification = async (
const text = `A new comment has been added against the red flag submitted by ${options.submitter}. Flag type: ${options.type}. You can view it here: ${baseURL}/publications/${options.publicationId}/flag/${options.flagId}`;

return send({
html: standardHTMLEmailTemplate('Red flag updated', html),
html: standardHTMLEmailTemplate('Red flag updated', html, `${options.submitter} has added a comment`),
text,
to: options.to,
subject: 'Red flag updated'
Expand Down Expand Up @@ -411,7 +425,11 @@ export const resolveRedFlagAuthorNotification = async (
const text = `A red flag has been resolved for '${options.publicationName}'. Flag type: ${options.type}. You can view it here: ${baseURL}/publications/${options.publicationId}/flag/${options.flagId}`;

return send({
html: standardHTMLEmailTemplate('Red flag resolved', html),
html: standardHTMLEmailTemplate(
'Red flag resolved',
html,
'It will no longer appear prominently against the publication'
),
text,
to: options.to,
subject: 'Red flag resolved'
Expand Down Expand Up @@ -441,7 +459,7 @@ export const resolveRedFlagCreatorNotification = async (
const text = `Thank you for resolving the red flag you created for '${options.publicationName}'. You can view it here: ${baseURL}/publications/${options.publicationId}/flag/${options.flagId}`;

return send({
html: standardHTMLEmailTemplate('Red flag resolved', html),
html: standardHTMLEmailTemplate('Red flag resolved', html, "The publication's author has been notified"),
text,
to: options.to,
subject: 'Red flag resolved'
Expand Down Expand Up @@ -491,7 +509,11 @@ export const notifyCoAuthorConfirmation = async (options: NotifyCoAuthorConfirma
} still need to confirm your draft before this publication can go live. Note that all co-authors must approve before this publication can go live`;

await send({
html: standardHTMLEmailTemplate('A co-author has approved your Octopus publication', html),
html: standardHTMLEmailTemplate(
'A co-author has approved your Octopus publication',
html,
'One step closer to going live'
),
text,
to: options.publication.authorEmail,
subject: 'A co-author has approved your Octopus publication'
Expand All @@ -514,7 +536,11 @@ export const notifyCoAuthorConfirmation = async (options: NotifyCoAuthorConfirma
const text = `All co-authors have confirmed their involvement in '${options.publication.title}' and have confirmed that the draft is ready to publish. You are now ready to publish! You can view the publication here: ${options.publication.url} . Note that any changes to the draft publication at this stage will require co-authors to reapprove.`;

await send({
html: standardHTMLEmailTemplate('All co-authors have approved your Octopus publication', html),
html: standardHTMLEmailTemplate(
'All co-authors have approved your Octopus publication',
html,
'You are ready to publish!'
),
text,
to: options.publication.authorEmail,
subject: 'All co-authors have approved your Octopus publication'
Expand Down Expand Up @@ -543,7 +569,11 @@ export const notifyCoAuthorRejection = async (options: NotifyCoAuthorRejection):
const text = `The request that you sent to ${options.coAuthor.email} to be register as a co-author of '${options.publication.title}' has been rejected, and this individual has denied their involvement. If you feel that this may have been a mistake, please check that the email address was spelled correctly, or contact this individual directly to discuss their involvement. This individual’s approval is no longer required before this publication can go live.`;

await send({
html: standardHTMLEmailTemplate('A co-author has denied their involvement', html),
html: standardHTMLEmailTemplate(
'A co-author has denied their involvement',
html,
'Their approval is no longer required to go live'
),
text,
to: options.publication.authorEmail,
subject: 'A co-author has denied their involvement'
Expand All @@ -568,7 +598,11 @@ export const notifyCoAuthorRemoval = async (options: NotifyCoAuthorRemoval): Pro
const text = `You are no longer listed as a co-author on '${options.publication.title}' and will not receive emails about updates to this publication in future. If you feel that this may have been a mistake, you may wish to contact the author directly to discuss your involvement.`;

await send({
html: standardHTMLEmailTemplate('You are no longer listed as a co-author', html),
html: standardHTMLEmailTemplate(
'You are no longer listed as a co-author',
html,
"You won't receive any more updates about this publication"
),
text,
to: options.coAuthor.email,
subject: 'You are no longer listed as a co-author'
Expand Down Expand Up @@ -608,7 +642,11 @@ export const sendApprovalReminder = async (options: SendApprovalReminder): Promi
const text = `${options.publication.creator} has sent you a reminder to confirm or deny your involvement as an author of the following publication on Octopus: ${options.publication.title}. To confirm your involvement, and see a preview of the publication, follow this link: ${baseURL}/author-link?email=${options.coAuthor.email}&code=${options.coAuthor.code}&publicationId=${options.publication.id}&versionId=${options.publication.versionId}&approve=true. If you are not the co-author, follow this link: ${baseURL}/author-link?email=${options.coAuthor.email}&code=${options.coAuthor.code}&publicationId=${options.publication.id}&versionId=${options.publication.versionId}&approve=false. An Octopus user has provided this email address so that you can receive this message. If you select that you are not involved with the publication named above, your data will be deleted immediately.`;

await send({
html: standardHTMLEmailTemplate('You’ve been added as a co-author on Octopus', html),
html: standardHTMLEmailTemplate(
'You’ve been added as a co-author on Octopus',
html,
`A reminder from ${options.publication.creator}`
),
text,
to: options.coAuthor.email,
subject: 'You’ve been added as a co-author on Octopus'
Expand Down Expand Up @@ -641,7 +679,11 @@ export const notifyCoAuthorsAboutChanges = async (options: NotifyCoAuthorsAboutC
const text = `The corresponding author has made changes to a publication you are involved with. Please use the link below to review the draft publication to ensure you are happy with the changes: ${options.publication.url} . Your approval is required before the corresponding author can publish. If you have any concerns with the publication, please contact the corresponding author directly to discuss them.`;

await send({
html: standardHTMLEmailTemplate('Changes have been made to a publication that you are an author on', html),
html: standardHTMLEmailTemplate(
'Changes have been made to a publication that you are an author on',
html,
'These are waiting for your review'
),
text,
to: options.coAuthor.email,
subject: 'Changes have been made to a publication that you are an author on'
Expand Down Expand Up @@ -669,7 +711,11 @@ export const notifyCoAuthorCancelledApproval = async (options: NotifyCoAuthorCan
const text = `A co-author had previously approved your publication, ${options.publication.title}, but has now changed their mind, indicating that changes might be needed. You can view the publication following this link: ${options.publication.url}. This author’s approval is required before publishing. Please discuss whether any further changes are needed with the author.`;

await send({
html: standardHTMLEmailTemplate('A co-author has cancelled their approval', html),
html: standardHTMLEmailTemplate(
'A co-author has cancelled their approval',
html,
'You may need to discuss their concerns directly to proceed'
),
text,
to: options.publication.authorEmail,
subject: 'A co-author has cancelled their approval'
Expand Down

0 comments on commit 503ce0b

Please sign in to comment.