(params: {
to: string
cc?: string | null
bcc?: string | null
subject?: string | null
body: string
contentType?: 'text' | 'html'
inReplyTo?: string
references?: string
})
| 419 | * @returns Base64url encoded raw message |
| 420 | */ |
| 421 | export function buildSimpleEmailMessage(params: { |
| 422 | to: string |
| 423 | cc?: string | null |
| 424 | bcc?: string | null |
| 425 | subject?: string | null |
| 426 | body: string |
| 427 | contentType?: 'text' | 'html' |
| 428 | inReplyTo?: string |
| 429 | references?: string |
| 430 | }): string { |
| 431 | const { to, cc, bcc, subject, body, contentType, inReplyTo, references } = params |
| 432 | const boundary = generateBoundary() |
| 433 | const { plain, html } = buildBodyAlternatives(body, contentType) |
| 434 | |
| 435 | const emailHeaders = ['MIME-Version: 1.0', `To: ${to}`] |
| 436 | |
| 437 | if (cc) { |
| 438 | emailHeaders.push(`Cc: ${cc}`) |
| 439 | } |
| 440 | if (bcc) { |
| 441 | emailHeaders.push(`Bcc: ${bcc}`) |
| 442 | } |
| 443 | |
| 444 | emailHeaders.push(`Subject: ${encodeRfc2047(subject || '')}`) |
| 445 | |
| 446 | if (inReplyTo) { |
| 447 | emailHeaders.push(`In-Reply-To: ${inReplyTo}`) |
| 448 | const referencesChain = references ? `${references} ${inReplyTo}` : inReplyTo |
| 449 | emailHeaders.push(`References: ${referencesChain}`) |
| 450 | } |
| 451 | |
| 452 | emailHeaders.push(`Content-Type: multipart/alternative; boundary="${boundary}"`) |
| 453 | emailHeaders.push('') |
| 454 | emailHeaders.push(...renderAlternativeParts(plain, html, boundary)) |
| 455 | |
| 456 | const email = emailHeaders.join('\n') |
| 457 | return Buffer.from(email).toString('base64url') |
| 458 | } |
| 459 | |
| 460 | /** |
| 461 | * Build a MIME multipart message with optional attachments |
no test coverage detected