sendEmail
this is a backend typescript component/function
send demo email w/ dw (to verify SMTP settings)
import { sendEmail } from "@/lib/dw-email";
const result = await sendEmail({ from: `Jonathan Youngblood (via ${import.meta.env.SITE_TITLE} contact form) <${import.meta.env.SMTP_USER}>`, subject: `[LWOA] Test`, message: { template: "@/email-templates/demo", data: { name: "Jonathan Youngblood", subject: "Test", message: "Test", siteName: import.meta.env.SITE_TITLE, }, },});
NORMAL TSX VERSION
import { sendEmail } from "@/lib/dw-email";
const result = await sendEmail({ from: `${import.meta.env.SITE_TITLE} <${import.meta.env.SMTP_USER}>`, subject: 'DEMO EMAIL', message: { template: '@/email-templates/demo', // ideal path, .tsx optional // template: '@/email-templates/demo.tsx', // template: 'src/email-templates/demo.tsx', // template: './src/email-templates/demo.tsx', // template: '../../src/email-templates/demo.tsx', data: { name: 'JY', surname: 'HX', tel: '1234567890' } },});
return new Response(JSON.stringify(result), { status: result.success ? 200 : 500, headers: { 'Content-Type': 'application/json' }})
TEXT ONLY
const result = await sendEmail({ from: `${import.meta.env.SITE_TITLE} <${import.meta.env.SMTP_USER}>`, subject: 'DEMO EMAIL', message: { text: `nice shot (should be the only text) - from your friends at ${import.meta.env.SITE_TITLE}`, },});
html only (no template)
const result = await sendEmail({ from: `${import.meta.env.SITE_TITLE} <${import.meta.env.SMTP_USER}>`, subject: 'DEMO EMAIL', message: { html: `<p>nice shot (should be the <b>only</b> text)</p> <p>from your friends at ${import.meta.env.SITE_TITLE}</p>`, text: `SEPARATE TEXT FALLBACK - nice shot (should be the only text) from your friends at ${import.meta.env.SITE_TITLE}`, },});
multiple recipients
const result = await sendEmail({ from: `${import.meta.env.SITE_TITLE} <${import.meta.env.SMTP_USER}>`, subject: 'DEMO EMAIL', message: { html: `<p>nice shot (should be the <b>only</b> text)</p> <p>from your friends at ${import.meta.env.SITE_TITLE}</p>`, },});
cc & bcc & replyto
const result = await sendEmail({ from: `${import.meta.env.SITE_TITLE} <${import.meta.env.SMTP_USER}>`, subject: 'DIFFERENT ANOTHER DEMO EMAIL - demo CC & BCC & replyto', message: { html: `<h1>👯♂️ HEY MAN 🤗</h1><p>nice shot</p> <p>from your friends at ${import.meta.env.SITE_TITLE}</p>`, },});