Dhesend

Node.js

Bun

Learn how to send your first email using Bun and the Dhesend Node.js SDK.

Prerequisites
To get the most out of this guide, you’ll need to:
1. Install
Get the Dhesend Node.js SDK.
1npm install dhesend
2. Create an email template

Start by creating your email template on 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);
3. Send email using html

Create a new file index.ts and send your first email.

1import Dhesend from "dhesend";
2import { EmailTemplate } from './email-template';
3
4const dhesend = new Dhesend(process.env.DHESEND_API_KEY);
5
6const server = Bun.serve({
7    port: 3000,
8    async fetch() {
9        const { data, error } = await dhesend.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 new Response(JSON.stringify({ error }));
18        };
19
20        return new Response(JSON.stringify({ data }));
21    },
22});
23
24console.log(`Bun listening on http://localhost:${server.port}`);

Start the local server by running bun index.tsx and navigate to http://localhost:3000.

Dhesend @ 2024 - Made with ❤ by  DHEM