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