feat(smartmail): Add new email validation helper methods (getMxRecords, isDisposableEmail, isRoleAccount) and an applyVariables method to Smartmail for dynamic templating.

This commit is contained in:
2025-05-07 14:57:50 +00:00
parent ffe324a9dc
commit f08544d53a
4 changed files with 94 additions and 1 deletions

View File

@@ -73,6 +73,32 @@ export class Smartmail<T> {
const smartmustache = new plugins.smartmustache.SmartMustache(this.options.subject);
return smartmustache.applyData(dataArg);
}
/**
* Applies variables to all template strings in the email
* @param variables Variables to apply to templates
*/
public applyVariables(variables: Record<string, any>): void {
if (!variables || typeof variables !== 'object') {
return;
}
// Process the subject, body, and HTML body with the provided variables
if (this.options.subject) {
const subjectMustache = new plugins.smartmustache.SmartMustache(this.options.subject);
this.options.subject = subjectMustache.applyData(variables);
}
if (this.options.body) {
const bodyMustache = new plugins.smartmustache.SmartMustache(this.options.body);
this.options.body = bodyMustache.applyData(variables);
}
if (this.options.htmlBody) {
const htmlBodyMustache = new plugins.smartmustache.SmartMustache(this.options.htmlBody);
this.options.htmlBody = htmlBodyMustache.applyData(variables);
}
}
/**
* Gets the processed plain text body with template variables applied