MCPcopy
hub / github.com/simstudioai/sim / buildSimpleEmailMessage

Function buildSimpleEmailMessage

apps/sim/tools/gmail/utils.ts:421–458  ·  view source on GitHub ↗
(params: {
  to: string
  cc?: string | null
  bcc?: string | null
  subject?: string | null
  body: string
  contentType?: 'text' | 'html'
  inReplyTo?: string
  references?: string
})

Source from the content-addressed store, hash-verified

419 * @returns Base64url encoded raw message
420 */
421export 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

Callers 4

utils.test.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90

Calls 7

generateBoundaryFunction · 0.85
buildBodyAlternativesFunction · 0.85
encodeRfc2047Function · 0.85
renderAlternativePartsFunction · 0.85
joinMethod · 0.80
pushMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected