Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
Node js unable to catch errors when sending an email using AWS SES

I need to be able to catch the error that occurs during the process of sending an email using Express and AWS SES. If there occurs an error, wrong email for example, the API itself shows a CORS error while in nodemon console the error is logged there.

const AWS = require('aws-sdk');

const SES_CONFIG = {
    accessKeyId: '...',
    secretAccessKey: '...',
    region: '...',
};

const AWS_SES = new AWS.SES(SES_CONFIG);

let sendEmail = (recipientEmail, name) => {
    let params = {
        Source: '...@gmail.com',
        Destination: {
            ToAddresses: [
                recipientEmail
            ],
        },
        ReplyToAddresses: [],
        Message: {
            Body: {
                Html: {
                    Charset: 'UTF-8',
                    Data: 'This is the body of my email!',
                },
            },
            Subject: {
                Charset: 'UTF-8',
                Data: `Hello, ${name}!`,
            }
        },
    };
    return AWS_SES.sendEmail(params).promise();
};

The API endpoint:

router.post('/emailTest', async (req, res) => {
    try {
        sendEmail('...@gmail.com', '...', function (err, data) {
            if (err)
                res.send(err);
            res.send(data);
        });

    } catch (error) {
        res.json({
            Status: 500,
            header: 'Error',
            message: 'Internal Server Error. ' + error.message
        });
    } })
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are calling your sendEmail function with a callback, but your function doesn't use any callbacks. It returns a promise.

Try using await.

router.post('/emailTest', async (req, res) => {
    try {
        const data = await sendEmail('...@gmail.com', '...');
        res.send(data);
    } catch (error) {
        res.json({
            Status: 500,
            header: 'Error',
            message: 'Internal Server Error. ' + error.message
        });
    } })
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda