mirror of
https://github.com/Unleash/unleash.git
synced 2025-06-23 01:16:27 +02:00
feat(productiviy-report): email config (#8571)
Add ability to customize email headers for non-transactional emails.
This commit is contained in:
parent
9809316a65
commit
30c14ff995
@ -53,6 +53,7 @@ exports[`should create default config 1`] = `
|
|||||||
"disableScheduler": undefined,
|
"disableScheduler": undefined,
|
||||||
"email": {
|
"email": {
|
||||||
"host": undefined,
|
"host": undefined,
|
||||||
|
"optionalHeaders": {},
|
||||||
"port": 587,
|
"port": 587,
|
||||||
"secure": false,
|
"secure": false,
|
||||||
"sender": "Unleash <noreply@getunleash.io>",
|
"sender": "Unleash <noreply@getunleash.io>",
|
||||||
|
@ -39,6 +39,7 @@ import {
|
|||||||
} from './types/models/api-token';
|
} from './types/models/api-token';
|
||||||
import {
|
import {
|
||||||
parseEnvVarBoolean,
|
parseEnvVarBoolean,
|
||||||
|
parseEnvVarJSON,
|
||||||
parseEnvVarNumber,
|
parseEnvVarNumber,
|
||||||
parseEnvVarStrings,
|
parseEnvVarStrings,
|
||||||
} from './util/parseEnvVar';
|
} from './util/parseEnvVar';
|
||||||
@ -348,6 +349,7 @@ const defaultEmail: IEmailOption = {
|
|||||||
sender: process.env.EMAIL_SENDER || 'Unleash <noreply@getunleash.io>',
|
sender: process.env.EMAIL_SENDER || 'Unleash <noreply@getunleash.io>',
|
||||||
smtpuser: process.env.EMAIL_USER,
|
smtpuser: process.env.EMAIL_USER,
|
||||||
smtppass: process.env.EMAIL_PASSWORD,
|
smtppass: process.env.EMAIL_PASSWORD,
|
||||||
|
optionalHeaders: parseEnvVarJSON(process.env.EMAIL_OPTIONAL_HEADERS, {}),
|
||||||
};
|
};
|
||||||
|
|
||||||
const dbPort = (dbConfig: Partial<IDBOption>): Partial<IDBOption> => {
|
const dbPort = (dbConfig: Partial<IDBOption>): Partial<IDBOption> => {
|
||||||
|
@ -33,6 +33,7 @@ export interface IEmailEnvelope {
|
|||||||
path: string;
|
path: string;
|
||||||
cid: string;
|
cid: string;
|
||||||
}[];
|
}[];
|
||||||
|
headers?: Record<string, string>;
|
||||||
}
|
}
|
||||||
|
|
||||||
const RESET_MAIL_SUBJECT = 'Unleash - Reset your password';
|
const RESET_MAIL_SUBJECT = 'Unleash - Reset your password';
|
||||||
@ -536,11 +537,14 @@ export class EmailService {
|
|||||||
},
|
},
|
||||||
): Promise<IEmailEnvelope> {
|
): Promise<IEmailEnvelope> {
|
||||||
if (this.configured()) {
|
if (this.configured()) {
|
||||||
|
const unsubscribeUrl = '{{amazonSESUnsubscribeUrl}}'; // FIXME: Add unsubscribe URL
|
||||||
|
|
||||||
const context = {
|
const context = {
|
||||||
userName,
|
userName,
|
||||||
userEmail,
|
userEmail,
|
||||||
...metrics,
|
...metrics,
|
||||||
unleashUrl: this.config.server.unleashUrl,
|
unleashUrl: this.config.server.unleashUrl,
|
||||||
|
unsubscribeUrl,
|
||||||
};
|
};
|
||||||
|
|
||||||
const template = 'productivity-report';
|
const template = 'productivity-report';
|
||||||
@ -555,6 +559,16 @@ export class EmailService {
|
|||||||
TemplateFormat.PLAIN,
|
TemplateFormat.PLAIN,
|
||||||
context,
|
context,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const headers: Record<string, string> = {};
|
||||||
|
Object.entries(this.config.email.optionalHeaders || {}).forEach(
|
||||||
|
([key, value]) => {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
headers[key] = value;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
const email: IEmailEnvelope = {
|
const email: IEmailEnvelope = {
|
||||||
from: this.sender,
|
from: this.sender,
|
||||||
to: userEmail,
|
to: userEmail,
|
||||||
@ -569,7 +583,9 @@ export class EmailService {
|
|||||||
'unleashLogo',
|
'unleashLogo',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
};
|
headers,
|
||||||
|
} satisfies IEmailEnvelope;
|
||||||
|
|
||||||
process.nextTick(() => {
|
process.nextTick(() => {
|
||||||
this.mailer!.sendMail(email).then(
|
this.mailer!.sendMail(email).then(
|
||||||
() =>
|
() =>
|
||||||
|
@ -167,6 +167,7 @@ export interface IEmailOption {
|
|||||||
smtpuser?: string;
|
smtpuser?: string;
|
||||||
smtppass?: string;
|
smtppass?: string;
|
||||||
transportOptions?: SMTPTransport.Options;
|
transportOptions?: SMTPTransport.Options;
|
||||||
|
optionalHeaders?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IListeningPipe {
|
export interface IListeningPipe {
|
||||||
|
@ -38,3 +38,18 @@ export function parseEnvVarStrings(
|
|||||||
|
|
||||||
return defaultVal;
|
return defaultVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function parseEnvVarJSON(
|
||||||
|
envVar: string | undefined,
|
||||||
|
defaultVal: Record<string, unknown>,
|
||||||
|
): Record<string, unknown> {
|
||||||
|
if (envVar) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(envVar);
|
||||||
|
} catch (e) {
|
||||||
|
return defaultVal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultVal;
|
||||||
|
}
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
<title>Your Unleash Productivity Report</title>
|
<title>Your Unleash Productivity Report</title>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body style="font-family: Arial, sans-serif;background-color: #f9f9f9;color: #333;margin: 0;padding: 0;font-size:16px">
|
<body style="font-family: Arial, sans-serif;background-color: #f9f9f9;color: #333;margin: 0;padding: 12px 0;font-size:16px">
|
||||||
<div class="container"
|
<div class="container"
|
||||||
style="max-width: 600px;margin: 24px auto;background-color: #ffffff;border-radius: 8px;border: 1px solid #f0f0f5;overflow: hidden;">
|
style="max-width: 600px;margin: 24px auto;background-color: #ffffff;border-radius: 8px;border: 1px solid #f0f0f5;overflow: hidden;">
|
||||||
<div class="header" style="background-color: #6c65e5;padding: 20px;text-align: center;color: #ffffff;">
|
<div class="header" style="background-color: #6c65e5;padding: 20px;text-align: center;color: #ffffff;">
|
||||||
@ -72,8 +72,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="unsubscribe" style="font-size: 12px;color: #888;margin-top: 10px;">
|
<div class="unsubscribe" style="font-size: 12px;color: #888;margin-top: 10px;">
|
||||||
This email was sent to {{userEmail}}. You’ve received this as you are a user of Unleash.<br>
|
This email was sent to {{userEmail}}. You’ve received this as you are a user of Unleash.<br>
|
||||||
If you wish to unsubscribe from our newsletter, click <a
|
{{#unsubscribeUrl}}
|
||||||
href="https://example.com/unsubscribe">here</a>.
|
If you wish to unsubscribe from updated, click <a href="{{unsubscribeUrl}}">here</a>.
|
||||||
|
{{/unsubscribeUrl}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -3,3 +3,8 @@ Subject: Unleash productivity report
|
|||||||
Hello,
|
Hello,
|
||||||
|
|
||||||
Productivity report
|
Productivity report
|
||||||
|
{{! FIXME: create plaintext template }}
|
||||||
|
|
||||||
|
{{#unsubscribeUrl}}
|
||||||
|
If you wish to unsubscribe from updated, open {{unsubscribeUrl}}.
|
||||||
|
{{/unsubscribeUrl}}
|
||||||
|
Loading…
Reference in New Issue
Block a user