feat: send header (#5707)
This commit is contained in:
@@ -20,6 +20,7 @@ type SendMailOptions = {
|
||||
text: string;
|
||||
component: JSX.Element;
|
||||
headCSS?: string;
|
||||
unsubscribeUrl?: string;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -94,6 +95,14 @@ export class Mailer {
|
||||
subject: data.subject,
|
||||
html,
|
||||
text: data.text,
|
||||
list: data.unsubscribeUrl
|
||||
? {
|
||||
unsubscribe: {
|
||||
url: data.unsubscribeUrl,
|
||||
comment: "Unsubscribe from these emails",
|
||||
},
|
||||
}
|
||||
: undefined,
|
||||
attachments: env.isCloudHosted()
|
||||
? undefined
|
||||
: [
|
||||
|
||||
@@ -12,7 +12,10 @@ export interface EmailProps {
|
||||
to: string | null;
|
||||
}
|
||||
|
||||
export default abstract class BaseEmail<T extends EmailProps, S = unknown> {
|
||||
export default abstract class BaseEmail<
|
||||
T extends EmailProps,
|
||||
S extends Record<string, any>
|
||||
> {
|
||||
private props: T;
|
||||
private metadata?: NotificationMetadata;
|
||||
|
||||
@@ -103,6 +106,7 @@ export default abstract class BaseEmail<T extends EmailProps, S = unknown> {
|
||||
),
|
||||
text: this.renderAsText(data),
|
||||
headCSS: this.headCSS?.(data),
|
||||
unsubscribeUrl: data.unsubscribeUrl,
|
||||
});
|
||||
Metrics.increment("email.sent", {
|
||||
templateName,
|
||||
|
||||
@@ -16,7 +16,10 @@ type Props = EmailProps & {
|
||||
/**
|
||||
* Email sent to a user when they request to delete their account.
|
||||
*/
|
||||
export default class ConfirmUserDeleteEmail extends BaseEmail<Props> {
|
||||
export default class ConfirmUserDeleteEmail extends BaseEmail<
|
||||
Props,
|
||||
Record<string, any>
|
||||
> {
|
||||
protected subject() {
|
||||
return `Your account deletion request`;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,10 @@ type BeforeSendProps = {
|
||||
/**
|
||||
* Email sent to a user when their data export has failed for some reason.
|
||||
*/
|
||||
export default class ExportFailureEmail extends BaseEmail<Props> {
|
||||
export default class ExportFailureEmail extends BaseEmail<
|
||||
Props,
|
||||
BeforeSendProps
|
||||
> {
|
||||
protected async beforeSend({ userId }: Props) {
|
||||
return {
|
||||
unsubscribeUrl: NotificationSettingsHelper.unsubscribeUrl(
|
||||
|
||||
@@ -27,7 +27,10 @@ type BeforeSendProps = {
|
||||
* Email sent to a user when their data export has completed and is available
|
||||
* for download in the settings section.
|
||||
*/
|
||||
export default class ExportSuccessEmail extends BaseEmail<Props> {
|
||||
export default class ExportSuccessEmail extends BaseEmail<
|
||||
Props,
|
||||
BeforeSendProps
|
||||
> {
|
||||
protected async beforeSend({ userId }: Props) {
|
||||
return {
|
||||
unsubscribeUrl: NotificationSettingsHelper.unsubscribeUrl(
|
||||
|
||||
@@ -25,7 +25,10 @@ type BeforeSendProps = {
|
||||
/**
|
||||
* Email sent to a user when someone they invited successfully signs up.
|
||||
*/
|
||||
export default class InviteAcceptedEmail extends BaseEmail<Props> {
|
||||
export default class InviteAcceptedEmail extends BaseEmail<
|
||||
Props,
|
||||
BeforeSendProps
|
||||
> {
|
||||
protected async beforeSend({ inviterId }: Props) {
|
||||
return {
|
||||
unsubscribeUrl: NotificationSettingsHelper.unsubscribeUrl(
|
||||
|
||||
@@ -20,7 +20,7 @@ type Props = EmailProps & {
|
||||
/**
|
||||
* Email sent to an external user when an admin sends them an invite.
|
||||
*/
|
||||
export default class InviteEmail extends BaseEmail<Props> {
|
||||
export default class InviteEmail extends BaseEmail<Props, Record<string, any>> {
|
||||
protected subject({ actorName, teamName }: Props) {
|
||||
return `${actorName} invited you to join ${teamName}’s knowledge base`;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,10 @@ type Props = EmailProps & {
|
||||
* Email sent to an external user when an admin sends them an invite and they
|
||||
* haven't signed in after a few days.
|
||||
*/
|
||||
export default class InviteReminderEmail extends BaseEmail<Props> {
|
||||
export default class InviteReminderEmail extends BaseEmail<
|
||||
Props,
|
||||
Record<string, any>
|
||||
> {
|
||||
protected subject({ actorName, teamName }: Props) {
|
||||
return `Reminder: ${actorName} invited you to join ${teamName}’s knowledge base`;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ type Props = EmailProps & {
|
||||
/**
|
||||
* Email sent to a user when they request a magic sign-in link.
|
||||
*/
|
||||
export default class SigninEmail extends BaseEmail<Props> {
|
||||
export default class SigninEmail extends BaseEmail<Props, Record<string, any>> {
|
||||
protected subject() {
|
||||
return "Magic signin link";
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ type Props = EmailProps & {
|
||||
* Email sent to the creator of a webhook when the webhook has become disabled
|
||||
* due to repeated failure.
|
||||
*/
|
||||
export default class WebhookDisabledEmail extends BaseEmail<Props> {
|
||||
export default class WebhookDisabledEmail extends BaseEmail<
|
||||
Props,
|
||||
Record<string, any>
|
||||
> {
|
||||
protected subject() {
|
||||
return `Warning: Webhook disabled`;
|
||||
}
|
||||
|
||||
@@ -17,7 +17,10 @@ type Props = EmailProps & {
|
||||
* Email sent to a user when their account has just been created, or they signed
|
||||
* in for the first time from an invite.
|
||||
*/
|
||||
export default class WelcomeEmail extends BaseEmail<Props> {
|
||||
export default class WelcomeEmail extends BaseEmail<
|
||||
Props,
|
||||
Record<string, any>
|
||||
> {
|
||||
protected subject() {
|
||||
return `Welcome to ${env.APP_NAME}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user