import {createTransport} from "../../deps.deno_ext.ts";import {type DataMap} from "../pure/minipack.ts";
export interface MailMessage{ from: string; to: string[]; title: string; body: string; cc?: string[]; bcc?: string[]; files?: DataMap[];}
export async function smtpSend(path:string, message:MailMessage):Promise<void>{ const {protocol, hostname, port, username, password} = new URL(path);
if(protocol !== "smtp:" && protocol !== "smtps:"){ throw new Error(protocol); }
const smtp = createTransport({ host: hostname, port: Number(port), secure: protocol === "smtps:", auth: username ? { user: decodeURIComponent(username), pass: decodeURIComponent(password), } : undefined });
await smtp.sendMail({ from: message.from, to: message.to, cc: message.cc, attachments: message.files?.map(({name, body}) => ({filename: name, content: body})), bcc: message.bcc, subject: message.title, text: message.body });
smtp.close();}