fix(structure): Unify structure even further

This commit is contained in:
2025-05-27 18:00:14 +00:00
parent 243a45d24c
commit 2aeb52bf13
10 changed files with 231 additions and 115 deletions

View File

@ -11,7 +11,7 @@ export interface IAttachment {
export interface IEmailOptions {
from: string;
to: string | string[]; // Support multiple recipients
to?: string | string[]; // Optional for templates
cc?: string | string[]; // Optional CC recipients
bcc?: string | string[]; // Optional BCC recipients
subject: string;
@ -68,16 +68,14 @@ export class Email {
this.from = options.from;
// Handle to addresses (single or multiple)
this.to = this.parseRecipients(options.to);
this.to = options.to ? this.parseRecipients(options.to) : [];
// Handle optional cc and bcc
this.cc = options.cc ? this.parseRecipients(options.cc) : [];
this.bcc = options.bcc ? this.parseRecipients(options.bcc) : [];
// Validate that we have at least one recipient
if (this.to.length === 0 && this.cc.length === 0 && this.bcc.length === 0) {
throw new Error('Email must have at least one recipient');
}
// Note: Templates may be created without recipients
// Recipients will be added when the email is actually sent
// Set subject with sanitization
this.subject = this.sanitizeString(options.subject || '');