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