Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Adds CC email field #20

Merged
merged 2 commits into from
Jan 13, 2023
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
9 changes: 7 additions & 2 deletions src/collections/FormSubmissions/hooks/sendEmail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,26 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => {
message,
subject,
emailTo,
cc: emailCC,
bcc: emailBCC,
emailFrom,
emailFromName,
replyTo: emailReplyTo,
replyToName,
} = email;

const to = replaceDoubleCurlys(emailTo, submissionData);
const cc = emailCC ? replaceDoubleCurlys(emailCC, submissionData) : '';
const bcc = emailBCC ? replaceDoubleCurlys(emailBCC, submissionData) : '';
const from = replaceDoubleCurlys(emailFromName ? `"${emailFromName}" ` + emailFrom : emailFrom, submissionData);
const replyTo = replaceDoubleCurlys(replyToName ? `"${replyToName}" ` + emailReplyTo : emailReplyTo || emailFrom, submissionData);
const replyTo = replaceDoubleCurlys(replyToName ? `"${replyToName}" ` + emailReplyTo : emailReplyTo || emailFrom, submissionData);

if (to && from) {
return ({
to,
from,
cc,
bcc,
replyTo,
subject: replaceDoubleCurlys(subject, submissionData),
html: `<div>${serialize(message, submissionData)}</div>`
Expand All @@ -72,7 +78,6 @@ const sendEmail = async (beforeChangeData: any, formConfig: PluginConfig) => {
if (typeof beforeEmail === 'function') {
emailsToSend = await beforeEmail(formattedEmails);
}

const log = emailsToSend.map(({ html, ...rest }) => ({ ...rest }))

await Promise.all(
Expand Down
10 changes: 9 additions & 1 deletion src/collections/Forms/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,18 @@ export const generateFormCollection = (formConfig: PluginConfig): CollectionConf
label: 'Email To',
required: true,
admin: {
width: '50%',
width: '100%',
placeholder: 'Email Sender <[email protected]>'
},
},
{
type: 'text',
name: 'cc',
label: 'CC',
admin: {
width: '50%',
},
},
{
type: 'text',
name: 'bcc',
Expand Down
3 changes: 3 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ export type Email = {
emailTo: string
emailFrom: string
emailFromName?: string
cc?: string
bcc?: string
replyTo?: string
replyToName?: string
Expand All @@ -166,6 +167,8 @@ export type Email = {

export type FormattedEmail = {
to: string
cc?: string
bcc?: string
from: string
subject: string
html: string
Expand Down