title: how to send email using loop and update each record?
body: <p>I have implemented nodemailer for sending emails. for email detail like email id, subject and text I have a table in the db. in that table I had a flag (new, processed)to get the list of new records so that I can send mail of new records
  I am using for loop on the record list to send emails. the thing I want to know is once the mail is forwarded successfully I want to update the record flag in the db. I am using sequlize in node.js.</p>
  
  <pre class="lang-js prettyprint-override"><code>
  var WEBDialerList=[];
  var WEBDialerListCount;
  
  SqlObj.WEBDialer.findAll(
          {
              where: {
                  IsDeleted: 0,
                  Status: 'New'
              }
          }
      )
          .then(data =&gt; {
              WEBDialerList = JSON.parse(JSON.stringify(data));
              console.log("d.length")
              console.log(WEBDialerList.length)
              console.log("d.length")
              if (WEBDialerList.length &gt; 0) {
                  for (var i in WEBDialerList){//= 0; i &lt; WEBDialerList.length; i++) {
                      WEBDialerListCount = i;
  
                      "use strict";
                      const nodemailer = require("nodemailer");
                      let transporter = nodemailer.createTransport({
                          service: "Gmail",
                          auth: {
                              user: 'abc@gmail.com',
                              pass: '******'
                          }
                      });
                      var e = WEBDialerList[i].Email;
                      let mailOptions = {
  
                          from: '"ib ik" &lt;ib.ik2093@gmail.com&gt;',
                          to: e,
  
                          subject: "Test Email from Node.js",
                          text: " scheduler Hello, this is a test email.  I have configured my gmail account in node.js to send emails. I am checking, is it configured correctly.",// plain text body
                          html: "&lt;b&gt; " + WEBDialerList[i].WEBDialerId + " scheduler Hello, this is a test email.  I have configured my gmail account in node.js to send emails. I am checking, is it configured correctly.&lt;/b&gt;" // html body
                      };
                       transporter.sendMail(mailOptions, function (error, info) {
                          if (error) {
                              return console.log(error);
                          }
                          else {
                              console.log("Message sent1: ", info);
                              console.log(WEBDialerListCount)
                              transporter.close();
                          }
                      })
  
                  }
              }
          })
          .catch(function (err) {
              console.log(err)
          });
  
  
  
  
  
  </code></pre>
  
  <p>In transporter.sendMail I just get it at the end of the loop so it is difficult for me to get what records needs to be updated.</p>