refactor: replace sending transport from mail
to sendmail
This commit is contained in:
parent
5e4d833378
commit
2a49a679c6
50
src/send.ts
50
src/send.ts
|
@ -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()
|
||||
}
|
Loading…
Reference in a new issue