refactor: split transporter config and send function

This commit is contained in:
Julien Oculi 2024-03-29 16:02:26 +01:00
parent 3eb207d18c
commit 3095db5781
4 changed files with 65 additions and 14 deletions

View file

@ -14,7 +14,8 @@
"jsx-email": "npm:jsx-email@^1.10.12", "jsx-email": "npm:jsx-email@^1.10.12",
"nodemailer": "npm:nodemailer@^6.9.13", "nodemailer": "npm:nodemailer@^6.9.13",
"nodemailer-smime": "npm:nodemailer-smime@^1.1.0", "nodemailer-smime": "npm:nodemailer-smime@^1.1.0",
"preact": "npm:preact@^10.20.1" "preact": "npm:preact@^10.20.1",
"turndown": "npm:turndown@^7.1.3"
}, },
"compilerOptions": { "compilerOptions": {
"jsx": "react-jsx", "jsx": "react-jsx",

View file

@ -3,12 +3,16 @@
"packages": { "packages": {
"specifiers": { "specifiers": {
"npm:@types/nodemailer": "npm:@types/nodemailer@6.4.14", "npm:@types/nodemailer": "npm:@types/nodemailer@6.4.14",
"npm:html-to-md": "npm:html-to-md@0.8.5",
"npm:jsx-email@^1.10.12": "npm:jsx-email@1.10.12_@jsx-email+app-preview@1.2.5__react@18.2.0__react-dom@18.2.0___react@18.2.0__vite@4.5.3_react@18.2.0_vite@4.5.3_postcss@8.4.38", "npm:jsx-email@^1.10.12": "npm:jsx-email@1.10.12_@jsx-email+app-preview@1.2.5__react@18.2.0__react-dom@18.2.0___react@18.2.0__vite@4.5.3_react@18.2.0_vite@4.5.3_postcss@8.4.38",
"npm:node-html-markdown": "npm:node-html-markdown@1.3.0",
"npm:nodemailer-smime@^1.1.0": "npm:nodemailer-smime@1.1.0", "npm:nodemailer-smime@^1.1.0": "npm:nodemailer-smime@1.1.0",
"npm:nodemailer@^6.9.13": "npm:nodemailer@6.9.13", "npm:nodemailer@^6.9.13": "npm:nodemailer@6.9.13",
"npm:preact-render-to-string": "npm:preact-render-to-string@6.1.0_preact@10.20.1", "npm:preact-render-to-string": "npm:preact-render-to-string@6.1.0_preact@10.20.1",
"npm:preact@^10.20.1": "npm:preact@10.20.1", "npm:preact@^10.20.1": "npm:preact@10.20.1",
"npm:superjson@1.13.3": "npm:superjson@1.13.3" "npm:superjson@1.13.3": "npm:superjson@1.13.3",
"npm:turndown": "npm:turndown@7.1.3",
"npm:turndown@^7.1.3": "npm:turndown@7.1.3"
}, },
"npm": { "npm": {
"@alloc/quick-lru@5.2.0": { "@alloc/quick-lru@5.2.0": {
@ -1499,6 +1503,16 @@
"randomfill": "randomfill@1.0.4" "randomfill": "randomfill@1.0.4"
} }
}, },
"css-select@5.1.0": {
"integrity": "sha512-nwoRF1rvRRnnCqqY7updORDsuqKzqYJ28+oSMaJMMgOauh3fvwHqMS7EZpIPqK8GL+g9mKxF1vP/ZjSeNjEVHg==",
"dependencies": {
"boolbase": "boolbase@1.0.0",
"css-what": "css-what@6.1.0",
"domhandler": "domhandler@5.0.3",
"domutils": "domutils@3.1.0",
"nth-check": "nth-check@2.1.1"
}
},
"css-selector-parser@3.0.5": { "css-selector-parser@3.0.5": {
"integrity": "sha512-3itoDFbKUNx1eKmVpYMFyqKX04Ww9osZ+dLgrk6GEv6KMVeXUhUnp4I5X+evw+u3ZxVU6RFXSSRxlTeMh8bA+g==", "integrity": "sha512-3itoDFbKUNx1eKmVpYMFyqKX04Ww9osZ+dLgrk6GEv6KMVeXUhUnp4I5X+evw+u3ZxVU6RFXSSRxlTeMh8bA+g==",
"dependencies": {} "dependencies": {}
@ -1618,6 +1632,10 @@
"domelementtype": "domelementtype@2.3.0" "domelementtype": "domelementtype@2.3.0"
} }
}, },
"domino@2.1.6": {
"integrity": "sha512-3VdM/SXBZX2omc9JF9nOPCtDaYQ67BGp5CoLpIQlO2KCAPETs8TcDHacF26jXadGbvUteZzRTeos2fhID5+ucQ==",
"dependencies": {}
},
"domutils@3.1.0": { "domutils@3.1.0": {
"integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==", "integrity": "sha512-H78uMmQtI2AhgDJjWeQmHwJJ2bLPD3GMmO7Zja/ZZh84wkm+4ut+IUnUdRa8uCGX88DiVx1j6FRe1XfxEgjEZA==",
"dependencies": { "dependencies": {
@ -2128,6 +2146,10 @@
"space-separated-tokens": "space-separated-tokens@2.0.2" "space-separated-tokens": "space-separated-tokens@2.0.2"
} }
}, },
"he@1.2.0": {
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"dependencies": {}
},
"hmac-drbg@1.0.1": { "hmac-drbg@1.0.1": {
"integrity": "sha512-Tti3gMqLdZfhOQY1Mzf/AanLiqh1WTiJgEj26ZuYQ9fbkLomzGchCws4FyrSd4VkpBfiNhaE1On+lOz894jvXg==", "integrity": "sha512-Tti3gMqLdZfhOQY1Mzf/AanLiqh1WTiJgEj26ZuYQ9fbkLomzGchCws4FyrSd4VkpBfiNhaE1On+lOz894jvXg==",
"dependencies": { "dependencies": {
@ -2140,6 +2162,10 @@
"integrity": "sha512-XJMYQYY3rze+lUxVb3ufucdjyvbPEr6ZRx96K1Z3IjOdoNj4qRqnmn69XZuTL+DHGewHjgZW0vWezx5aJsV80g==", "integrity": "sha512-XJMYQYY3rze+lUxVb3ufucdjyvbPEr6ZRx96K1Z3IjOdoNj4qRqnmn69XZuTL+DHGewHjgZW0vWezx5aJsV80g==",
"dependencies": {} "dependencies": {}
}, },
"html-to-md@0.8.5": {
"integrity": "sha512-2AtBBJRrZ8WvhB1eDgTjW2TwVy1lat9FJW+XvVX836gsKi6qlhwaVG2jQZjbJAFr81/UW+6ABJSz/QOpeqgmuQ==",
"dependencies": {}
},
"html-to-text@9.0.5": { "html-to-text@9.0.5": {
"integrity": "sha512-qY60FjREgVZL03vJU6IfMV4GDjGBIoOyvuFdpBDIX9yTlDw0TjxVBQp+P8NvpdIXNJvfWBTNul7fsAQJq2FNpg==", "integrity": "sha512-qY60FjREgVZL03vJU6IfMV4GDjGBIoOyvuFdpBDIX9yTlDw0TjxVBQp+P8NvpdIXNJvfWBTNul7fsAQJq2FNpg==",
"dependencies": { "dependencies": {
@ -2582,6 +2608,19 @@
"integrity": "sha512-sol30LUpz1jQFBjOKwbjxijiE3b6pjd74YwfD0fJOKPjF+fONKb2Yg8rYgS6+bK6VDl+/wfr4IYpC7jDzLUIfw==", "integrity": "sha512-sol30LUpz1jQFBjOKwbjxijiE3b6pjd74YwfD0fJOKPjF+fONKb2Yg8rYgS6+bK6VDl+/wfr4IYpC7jDzLUIfw==",
"dependencies": {} "dependencies": {}
}, },
"node-html-markdown@1.3.0": {
"integrity": "sha512-OeFi3QwC/cPjvVKZ114tzzu+YoR+v9UXW5RwSXGUqGb0qCl0DvP406tzdL7SFn8pZrMyzXoisfG2zcuF9+zw4g==",
"dependencies": {
"node-html-parser": "node-html-parser@6.1.13"
}
},
"node-html-parser@6.1.13": {
"integrity": "sha512-qIsTMOY4C/dAa5Q5vsobRpOOvPfC4pB61UVW2uSwZNUp0QU/jCekTal1vMmbO0DgdHeLUJpv/ARmDqErVxA3Sg==",
"dependencies": {
"css-select": "css-select@5.1.0",
"he": "he@1.2.0"
}
},
"node-releases@2.0.14": { "node-releases@2.0.14": {
"integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==", "integrity": "sha512-y10wOWt8yZpqXmOgRo77WaHEmhYQYGNA6y421PKsKYWEK8aW+cqAphborZDhqfyKrbZEN92CN1X2KbafY2s7Yw==",
"dependencies": {} "dependencies": {}
@ -3613,6 +3652,12 @@
"integrity": "sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw==", "integrity": "sha512-C3TaO7K81YvjCgQH9Q1S3R3P3BtN3RIM8n+OvX4il1K1zgE8ZhI0op7kClgkxtutIE8hQrcrHBXvIheqKUUCxw==",
"dependencies": {} "dependencies": {}
}, },
"turndown@7.1.3": {
"integrity": "sha512-Z3/iJ6IWh8VBiACWQJaA5ulPQE5E1QwvBHj00uGzdQxdRnd8fh1DPqNOJqzQDu6DkOstORrtXzf/9adB+vMtEA==",
"dependencies": {
"domino": "domino@2.1.6"
}
},
"unified@11.0.4": { "unified@11.0.4": {
"integrity": "sha512-apMPnyLjAX+ty4OrNap7yumyVAMlKx5IWU2wlzzUdYJO9A8f1p9m/gywF/GM2ZDFcjQPrx59Mc90KwmxsoklxQ==", "integrity": "sha512-apMPnyLjAX+ty4OrNap7yumyVAMlKx5IWU2wlzzUdYJO9A8f1p9m/gywF/GM2ZDFcjQPrx59Mc90KwmxsoklxQ==",
"dependencies": { "dependencies": {
@ -3890,7 +3935,8 @@
"npm:jsx-email@^1.10.12", "npm:jsx-email@^1.10.12",
"npm:nodemailer-smime@^1.1.0", "npm:nodemailer-smime@^1.1.0",
"npm:nodemailer@^6.9.13", "npm:nodemailer@^6.9.13",
"npm:preact@^10.20.1" "npm:preact@^10.20.1",
"npm:turndown@^7.1.3"
] ]
} }
} }

15
src/send.ts Normal file
View file

@ -0,0 +1,15 @@
import { Mail } from '../types.ts'
import { transporter } from './transporter.ts'
export function send(mail: Mail) {
return transporter.sendMail({
from: mail.options.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: 'Text only',
html: mail.body.toString(),
attachments: mail.options.attachments.map((path) => ({ path })),
})
}

View file

@ -1,7 +1,6 @@
// @deno-types="npm:@types/nodemailer" // @deno-types="npm:@types/nodemailer"
import nodemailer from 'nodemailer' import nodemailer from 'nodemailer'
// import smime from 'nodemailer-smime' // import smime from 'nodemailer-smime'
import { Mail } from '../types.ts'
const dkimPrivateKey = await Deno.readTextFile( const dkimPrivateKey = await Deno.readTextFile(
'/home/julien/dkim_sendmail_keys/dkim_sendmail_cohabit_fr.pem', '/home/julien/dkim_sendmail_keys/dkim_sendmail_cohabit_fr.pem',
@ -24,13 +23,3 @@ export const transporter = nodemailer.createTransport({
}, },
}) })
// .use('stream', smime(smimeOptions)) // .use('stream', smime(smimeOptions))
export function send(mail: Mail) {
return transporter.sendMail({
from: mail.options.from.toString(),
to: mail.to.map((contact) => contact.toString()).join(', '),
subject: mail.subject,
text: 'Text only',
html: mail.body.toString(),
})
}