Node.js
Hono
Get started with sending emails in Hono using Dhesend Node.js SDK.
Prerequisites
To get the most out of this guide, you’ll need to:
2. Create an email template
Start by creating your email template on emails/email-template.tsx.
1interface EmailTemplateProps {
2 firstName: string;
3};
4
5export const EmailTemplate = ({ firstName }: EmailTemplateProps) => (
6 `<div>
7 <h1>Welcome, ${firstName}!</h1>
8 </div>`
9);To use JSX/TSX with Hono, we need to modify the tsconfig.json.
1{
2 "compilerOptions": {
3 "jsx": "react-jsx",
4 "jsxImportSource": "react"
5 }
6}3. Send email using html
Create a new file index.tsx and send your first email.
1import { Hono } from 'hono';
2import Dhesend from 'dhesend';
3import { EmailTemplate } from './emails/email-template';
4
5const app = new Hono();
6const dhesend = new Dhesend('re_123456789');
7
8app.get('/', async (c) => {
9 const { data, error } = await resend.emails.send({
10 from: "Dhesend <example@domain.com>",
11 to: ['example@dhesend.com'],
12 subject: 'Welcome to Dhesend',
13 htmlBody: EmailTemplate({ firstName: 'Ali' }),
14 });
15
16 if (error) {
17 return c.json(error, 400);
18 };
19
20 return c.json(data);
21});
22
23export default app;On this page