diff --git a/src/send.ts b/src/send.ts deleted file mode 100644 index 7e6a77d..0000000 --- a/src/send.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { render } from 'jsx-email' -import { Mail } from '../types.ts' - -export async function send(mail: Mail) { - const args: string[][] = [ - ['-s', mail.subject], - ['-a', `From: ${mail.options.from}`], - ['-a', `To: ${mail.to.map((contact) => contact.toString()).join(', ')}`], - ['-a', 'MIME-Version: 1.0'], - ['-a', `Content-Type: ${mail.options.contentType}`], - ] - - if (mail.options.cc.length) { - args.push([ - '-a', - `CC:${mail.options.cc.map((cc) => cc.toString()).join(', ')}`, - ]) - } - if (mail.options.cci.length) { - args.push([ - '-a', - `BCC:${mail.options.cci.map((cci) => cci.toString()).join(', ')}`, - ]) - } - if (mail.options.attachments.length) { - mail.options.attachments.forEach((attachment) => - args.push([`-A=${attachment}`]) - ) - } - args.push([mail.to.map((account) => account.address).join(', ')]) - - const cmd = new Deno.Command('/usr/bin/mail', { - args: args.flat(), - stdin: 'piped', - stderr: 'inherit', - stdout: 'inherit', - }) - - const process = cmd.spawn() - - const _body = typeof mail.body === 'string' - ? mail.body - : await render(mail.body) - - const writer = process.stdin.getWriter() - await writer.write(new TextEncoder().encode(mail.body.toString())) - await writer.close() - - await process.output() -}