Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

257
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!