Email utility functions including template rendering with graceful placeholder handling, RFC 5322 sender formatting, localized expiry date formatting, email redaction for logging, locale fallback, and SMTP error classification.
// Source: https://github.com/DouglasNeuroInformatics/OpenDataCapture | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
import type { Language, LocalizedString } from '@opendatacapture/schemas/core';
import type { MailConfig, MailEncryption, MailErrorCode } from '@opendatacapture/schemas/mail';
/**
* Substitute `{{key}}` placeholders in a template with the provided values.
* Unknown placeholders are left untouched so a malformed template degrades
* gracefully rather than throwing.
*/
export function renderTemplate(template: string, variables: { [key: string]: string }): string {
return template.replace(/\{\{\s*(\w+)\s*\}\}/g, (match, key: string) => {
return Object.protot
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key