Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

259
Visualizações
nodejs sending email with wrong body text

I am working with a javascript file that I am serving through NODE. It will take in input and then serialize it, and send an email. The code is:

let aws = require('aws-sdk'),
        ses = new aws.SES({ region: 'us-east-1' }),
        makeParams = request => {
            var emailBody = 'dooba dooba';
            console.log(request.body)
            for (var a in request.body) {
                // console.log(a);
                emailBody +=' test'
                console.log(emailBody);
                // emailBody += `${a}: ${request.body.a}<br />`
            }

            return {
                Destination: { /* required */
                    ToAddresses: [
//                      'xxxxx@gmail.com'
                        'xxxxx@gmail.com'
                    ]
                },
                Message: { /* required */
                    Body: { /* required */
                        Html: {
                            Data: emailBody, /* required */
                            Charset: 'UTF-8'
                        },
                        Text: {
                            // Data: emailBody.replace(/<br \/>/, "\r\n"), /* required */
                            Data: emailBody,
                            Charset: 'UTF-8'
                        }
                    },
                    Subject: { /* required */
                        Data: 'New Opportunity Submitted', /* required */
                        Charset: 'UTF-8'
                    }
                },
                Source: 'xxxxx@gmail.com'
                
            }
        },
        send = request => {
            return ses.sendEmail(makeParams(request)).promise();
        };

The script works as far as it takes an input and sends out the email, the problem is what it sends to the email. When I run it through node this is the output:

Welcome to Node.js v14.17.6.
Type ".help" for more information.
> let b = require('./app/bindings.js')
undefined
> b.send(b.makeParams({body: {foo:'bar',bar:'baz'}}))
{ foo: 'bar', bar: 'baz' }
loopy
loopy
outside: dooba dooba test test
sent
undefined
outside: dooba dooba
Promise { <pending> }
> .exit

The text that should be being sent to the email is the variable emailBody. It should be taking that and then appending to it, the input from send(b.makeParams(). In my code, I verified that the loop was running by logging "loopy" and then logging the final output.

It then should send that, which I see when it logs "send"; however I do not understand why it is going through again but skipping the loop. This is evidenced by the second "outside" which is after the "sent". So when I get the email instead of the body text displaying "dooba dooba test test" I get "dooba dooba".

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda