Implement support for Mailchimp and mandrill as an email service provider.
Add a new PersistedEmailProvider type:
|
export const PersistedEmailProvider = Type.Union([ |
|
SendgridEmailProvider, |
|
AmazonSesEmailProvider, |
|
PostMarkEmailProvider, |
|
ResendEmailProvider, |
|
SmtpEmailProvider, |
|
TestEmailProvider, |
|
]); |
Add new EmailServiceProviderSuccess type:
|
export const EmailServiceProviderSuccess = Type.Union([ |
|
EmailSendgridSuccess, |
|
EmailAmazonSesSuccess, |
|
EmailPostMarkSuccess, |
|
EmailResendSuccess, |
|
EmailSmtpSuccess, |
|
EmailTestSuccess, |
|
]); |
Add new EmailServiceProviderFailure type:
|
export const EmailServiceProviderFailure = Type.Union([ |
|
MessageSendgridServiceFailure, |
|
MessageAmazonSesServiceFailure, |
|
MessageResendFailure, |
|
MessagePostMarkFailure, |
|
MessageSmtpFailure, |
|
]); |
Add new EmailProviderSecret type:
|
export const EmailProviderSecret = Type.Union([ |
|
SendgridSecret, |
|
PostMarkSecret, |
|
AmazonSesSecret, |
|
SmtpSecret, |
|
ResendSecret, |
|
TestEmailSecret, |
|
]); |
Error handling for the /templates/test api endpoint:
|
switch (type) { |
|
case EmailProviderType.Sendgrid: { |
|
const { body, status } = result.error.variant.provider; |
|
const suggestions: string[] = []; |
|
if (status) { |
|
suggestions.push(`Sendgrid responded with status: ${status}`); |
|
if (status === 403) { |
|
suggestions.push( |
|
"Is the configured email domain authorized in sengrid?", |
|
); |
|
} |
|
} |
|
return reply.status(200).send({ |
|
type: JsonResultType.Err, |
|
err: { |
|
suggestions, |
|
responseData: body, |
|
}, |
|
}); |
|
} |
A webhook for updating the status of sent emails:
|
fastify.withTypeProvider<TypeBoxTypeProvider>().post( |
|
"/sendgrid", |
|
{ |
|
schema: { |
|
description: "Used to consume sendgrid webhook payloads.", |
|
tags: ["Webhooks"], |
|
headers: Type.Object({ |
|
"x-twilio-email-event-webhook-signature": Type.String(), |
|
"x-twilio-email-event-webhook-timestamp": Type.String(), |
|
}), |
|
body: Type.Array(SendgridEvent), |
|
}, |
|
}, |
Handle the email provider type when sending messages:
|
case EmailProviderType.Sendgrid: { |
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition |
|
if (secretConfig.type !== EmailProviderType.Sendgrid) { |
|
return err({ |
|
type: InternalEventType.BadWorkspaceConfiguration, |
|
variant: { |
|
type: BadWorkspaceConfigurationType.MessageServiceProviderMisconfigured, |
|
message: `expected sendgrid secret config but got ${secretConfig.type}`, |
|
}, |
|
}); |
|
} |
Create the email provider:
|
const val = emailProviders.flatMap((ep) => { |
|
let type: EmailProviderType; |
|
switch (ep.type) { |
|
case EmailProviderType.Test: |
|
type = EmailProviderType.Test; |
|
break; |
|
case EmailProviderType.Sendgrid: |
|
type = EmailProviderType.Sendgrid; |
|
break; |
|
case EmailProviderType.AmazonSes: |
Add Place in Settings to configure email provider:
|
function EmailChannelConfig() { |
|
return ( |
|
<> |
|
<SectionSubHeader id={settingsSectionIds.emailChannel} title="Email" /> |
|
<DefaultEmailConfig /> |
|
<SendGridConfig /> |
|
<AmazonSesConfig /> |
|
<ResendConfig /> |
|
<PostMarkConfig /> |
|
<SmtpConfig /> |
|
</> |
|
); |
|
} |
See this previous issue as a reference: #641
From SyncLinear.com | DF-500
Implement support for Mailchimp and mandrill as an email service provider.
Add a new
PersistedEmailProvidertype:dittofeed/packages/isomorphic-lib/src/types.ts
Lines 1465 to 1472 in 098d153
Add new
EmailServiceProviderSuccesstype:dittofeed/packages/isomorphic-lib/src/types.ts
Lines 3068 to 3075 in 098d153
Add new
EmailServiceProviderFailuretype:dittofeed/packages/isomorphic-lib/src/types.ts
Lines 3275 to 3281 in 098d153
Add new
EmailProviderSecrettype:dittofeed/packages/isomorphic-lib/src/types.ts
Lines 3610 to 3617 in 098d153
Error handling for the
/templates/testapi endpoint:dittofeed/packages/api/src/controllers/contentController.ts
Lines 418 to 437 in 098d153
A webhook for updating the status of sent emails:
dittofeed/packages/api/src/controllers/webhooksController.ts
Lines 68 to 80 in 098d153
Handle the email provider type when sending messages:
dittofeed/packages/backend-lib/src/messaging.ts
Lines 899 to 909 in 098d153
Create the email provider:
dittofeed/packages/backend-lib/src/messaging/email.ts
Lines 143 to 152 in 098d153
Add Place in Settings to configure email provider:
dittofeed/packages/dashboard/src/pages/settings.page.tsx
Lines 1060 to 1072 in 098d153
See this previous issue as a reference: #641
From SyncLinear.com | DF-500