DEV Community

Cover image for Envias Correo Electrónicos gratis con Resend Emails
Yosmar Hinestroza
Yosmar Hinestroza

Posted on

Envias Correo Electrónicos gratis con Resend Emails

Hola comunidad! en esta ocasión les traigo un pequeño ejemplo para poder crear tu propía API, para envios de Correo Eleéctronico

Todo esto es gracias a RESEND

Video Implementación

Envias Correo Electrónicos gratis con Resend Emails<br>

Se instalan las diferente Librerías

npm i express bodyParser cors Resend dotenv
Enter fullscreen mode Exit fullscreen mode

Se crea archivo server.js

import express from 'express';
import bodyParser from 'body-parser';
import cors from 'cors';
import { Resend } from 'resend';

const app = express();

app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

console.log(process.env.RESEND_API_KEY);
const PORT = process.env.PORT || 4002;
const resend = new Resend(process.env.RESEND_API_KEY ?? '')

app.get('/', (req, res) => {
    res.send('Hello World');
})

app.post('/send-email',  async (req, res) => {
    try {
        const { from, to, subject, html } = req.body;
        const response = await resend.emails.send({ from, to, subject, html });
        res.status(200).send(response);
      } catch (error) {
        res.status(500).send({ error: 'Failed to send email' });
      }
})



app.listen(PORT, () => {
    console.log(`Server is running on port localhost:${PORT}`);
});
Enter fullscreen mode Exit fullscreen mode

En el archivo package.json editar la siguiente linea

"scripts": {
    "start": "node -r dotenv/config ./src/server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },

Enter fullscreen mode Exit fullscreen mode

Image of Timescale

Timescale – the developer's data platform for modern apps, built on PostgreSQL

Timescale Cloud is PostgreSQL optimized for speed, scale, and performance. Over 3 million IoT, AI, crypto, and dev tool apps are powered by Timescale. Try it free today! No credit card required.

Try free

Top comments (0)

Cloudinary image

Video API: manage, encode, and optimize for any device, channel or network condition. Deliver branded video experiences in minutes and get deep engagement insights.

Learn more

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay