Skip to main content
Module

x/darkflare/Mail.ts

The API Engine
Go to Latest
File
/// <reference types='./internal.d.ts' />
export class Mail { constructor(options: { subject: string, message: string, author: { name: string, email: string }, recipient: { name?: string, email: string } | string | { name?: string, email: string }[] | string[] }) { const recipients: { name?: string, email: string }[] = []
if (typeof options.recipient === 'string') { recipients.push({ email: options.recipient }) } else if (options.recipient instanceof Array) { for (const recipient of options.recipient) recipients.push(typeof recipient === 'string' ? { email: recipient } : recipient) } else { recipients.push(options.recipient) }
window.__darkflare.waitUntil(fetch('https://api.mailchannels.net/tx/v1/send', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ personalizations: [{ to: recipients }], from: options.author, subject: options.subject, content: [{ type: options.message.startsWith('<html>') ? 'text/html' : 'text/plain', value: options.message }] }) })) }}