feat(chore): lazy load dkim key
This commit is contained in:
parent
b43c5e5451
commit
07be4fdb95
|
@ -5,7 +5,7 @@ import { transporter } from './transporter.ts'
|
|||
export async function send(mail: Mail) {
|
||||
const { html, text } = await renderTemplate(mail.body)
|
||||
|
||||
return transporter.sendMail({
|
||||
return (await transporter()).sendMail({
|
||||
from: mail.from.toString(),
|
||||
to: mail.to.map((contact) => contact.toString()),
|
||||
cc: mail.options.cc.map((cc) => cc.toString()),
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
// @deno-types="npm:@types/nodemailer"
|
||||
import nodemailer from 'nodemailer'
|
||||
|
||||
const dkimPath = '/home/julien/dkim_sendmail_keys/dkim_sendmail_cohabit_fr.pem'
|
||||
const dkimPrivateKey = await Deno.readTextFile(dkimPath).catch((cause) => {
|
||||
export async function transporter() {
|
||||
const dkimPath =
|
||||
'/home/julien/dkim_sendmail_keys/dkim_sendmail_cohabit_fr.pem'
|
||||
const dkimPrivateKey = await Deno.readTextFile(dkimPath).catch((cause) => {
|
||||
throw new Error(`unable to load DKIM private key from "${dkimPath}"`, {
|
||||
cause,
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
export const transporter = nodemailer.createTransport({
|
||||
return nodemailer.createTransport({
|
||||
sendmail: true,
|
||||
newline: 'unix',
|
||||
path: '/usr/sbin/sendmail',
|
||||
|
@ -17,4 +19,5 @@ export const transporter = nodemailer.createTransport({
|
|||
keySelector: 'sendmailY2024M03',
|
||||
privateKey: dkimPrivateKey,
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue