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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user