Logo

dev-resources.site

for different kinds of informations.

Envias Correo Electr贸nicos gratis con Resend Emails

Published at
1/8/2025
Categories
webdev
programming
spanish
resend
Author
Yosmar Hinestroza
Categories
4 categories in total
webdev
open
programming
open
spanish
open
resend
open
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

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}`);
});

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"
  },

Featured ones: