mailer/src/send.ts

26 lines
710 B
TypeScript
Raw Normal View History

2024-03-29 16:37:35 +01:00
import type { Mail } from '../types.ts'
import { renderTemplate } from './template.tsx'
import { transporter } from './transporter.ts'
export async function send(mail: Mail) {
const { html, text } = await renderTemplate(mail.body)
2024-04-03 17:05:55 +02:00
return (await transporter()).sendMail({
2024-03-29 16:06:20 +01:00
from: mail.from.toString(),
to: mail.to.map((contact) => contact.toString()),
cc: mail.options.cc.map((cc) => cc.toString()),
bcc: mail.options.cci.map((cci) => cci.toString()),
subject: mail.subject,
text,
html,
attachments: [
{
cid: 'cohabit_logo.svg',
path: 'https://cohabit.fr/images/logo.svg',
filename: 'cohabit_logo.svg',
},
...mail.options.attachments.map((path) => ({ path })),
],
})
}