11import nodemailer from "nodemailer" ;
2+ import {
3+ inlineDataImagesAsCid ,
4+ type InlineImageAttachment ,
5+ } from "../_shared/inline-images.ts" ;
26
37const host = Deno . env . get ( "SMTP_HOST" ) ;
48const port = Deno . env . get ( "SMTP_PORT" ) ;
@@ -10,6 +14,7 @@ type SendEmailOptions = {
1014 from ?: string ;
1115 replyTo ?: string ;
1216 text ?: string ;
17+ attachments ?: InlineImageAttachment [ ] ;
1318 transport ?: {
1419 host : string ;
1520 port : number ;
@@ -35,7 +40,9 @@ function getDefaultTransport() {
3540 } ;
3641}
3742
38- export async function verifyTransport ( transport ?: SendEmailOptions [ "transport" ] ) {
43+ export async function verifyTransport (
44+ transport ?: SendEmailOptions [ "transport" ] ,
45+ ) {
3946 const transporter = nodemailer . createTransport (
4047 transport ?? getDefaultTransport ( ) ,
4148 ) ;
@@ -51,16 +58,22 @@ export async function sendEmail(
5158 const transporter = nodemailer . createTransport (
5259 options . transport ?? getDefaultTransport ( ) ,
5360 ) ;
61+ const inlinePayload = inlineDataImagesAsCid ( html ) ;
62+ const attachments = [
63+ ...( options . attachments ?? [ ] ) ,
64+ ...inlinePayload . attachments ,
65+ ] ;
5466
5567 const info = await transporter . sendMail ( {
5668 from : options . from ?? defaultFrom ,
5769 to,
5870 subject,
59- html,
71+ html : inlinePayload . html ,
6072 text : options . text ,
6173 replyTo : options . replyTo ,
74+ attachments,
6275 } ) ;
6376
6477 console . log ( "Email sent:" , { to, messageId : info . messageId } ) ;
6578 // console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info)); // For local testing only
66- }
79+ }
0 commit comments