2024-03-29 16:37:35 +01:00
|
|
|
import type { Mail } from '../types.ts'
|
2024-04-02 15:47:06 +02:00
|
|
|
import { renderTemplate } from './template.tsx'
|
2024-03-29 16:02:26 +01:00
|
|
|
import { transporter } from './transporter.ts'
|
|
|
|
|
2024-04-02 15:47:06 +02:00
|
|
|
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(),
|
2024-03-29 16:02:26 +01:00
|
|
|
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,
|
2024-04-02 15:47:06 +02:00
|
|
|
text,
|
|
|
|
html,
|
2024-04-11 16:51:05 +02:00
|
|
|
attachments: [
|
|
|
|
{
|
|
|
|
cid: 'cohabit_logo.svg',
|
|
|
|
path: 'https://cohabit.fr/images/logo.svg',
|
|
|
|
filename: 'cohabit_logo.svg',
|
|
|
|
},
|
|
|
|
...mail.options.attachments.map((path) => ({ path })),
|
|
|
|
],
|
2024-03-29 16:02:26 +01:00
|
|
|
})
|
|
|
|
}
|