Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
361 views
in Technique[技术] by (71.8m points)

javascript - nodemailer failing on email send

I have been using node mailer for about 6 months, if not more, and I've ran into no issues at all, but all of a sudden today I've been getting this error, and I cannot figure out how to fix it. Wondering if anyone has received such error before?

 Error: read ECONNRESET
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:205:27) {
  errno: 'ECONNRESET',
  code: 'ECONNRESET',
  syscall: 'read',
  type: 'FETCH',
  sourceUrl: 'https://api.nodemailer.com/user'
}

here is my code that has been working for months:

 // async..await is not allowed in global scope, must use a wrapper
  async function main() {
    // Generate test SMTP service account from ethereal.email
    // Only needed if you don't have a real mail account for testing
    let testAccount = await nodemailer.createTestAccount();
  
    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
      service: 'Gmail', 
          auth: {
                  user: process.env.GMAIL_EMAIL,
                  pass: process.env.GMAIL_PASS
              }
    });  
    // select * from db to show in email

    var showingOrderProducts = "select * from " + tableName
    console.log("table name is ", tableName)
        console.log('Grabbing Products and Quantity for email send', showingOrderProducts);
        ibmdb.open(ibmdbconn, function (err,conn) {
            if (err) return console.log(err);
            conn.query(showingOrderProducts, function (err, data) {
                if (err) {
                    console.log(err)
                }
        
                if(data.length){ 
                    for(var i = 0;i < data.length;i++) {

                        PRODUCTS = PRODUCTS + data[i].ITEMDESC + " - " + data[i].QTY + "(SIZE: " + data[i].SIZE + ")
"
                        console.log(PRODUCTS)
                    }
                }

                console.log("PRODUCTS is : " + PRODUCTS)

                var to_addr = req.body.user_email
                
  
                // send mail with defined transport object
                let info = transporter.sendMail({
                  from: "[email protected]", // sender address
                  to: to_addr, // list of receivers
                  subject: "Order for " + req.body.user_company, // Subject line
                 // text: PRODUCTS
                   text: "Thank you " + req.body.user_name + " for ordering with ... Products! 

The Information you entered is as follows:

 Phone Number " + req.body.user_phoneNumber + "

 Company: " + req.body.user_company + "

 Location: " + req.body.user_location + "

 Branch Number " + req.body.user_BranchNumber + "

 PO Number: " + req.body.user_ponumber + "

 Products Ordered: 
" + PRODUCTS + "

Your order total is: $" + req.body.priceTotal + "

 This total does not include shipping costs, and you will be notified about shipping costs within the next 24 hours! 

 Sincerly, 
 Exclusive Products" // plain text body
                });

                let info2 = transporter.sendMail({
                    from: "[email protected]", // sender address
                    to: "x, // list of receivers : [email protected]
                    subject: "Order for " + req.body.user_company, // Subject line
                   // text: PRODUCTS
                     text: "A NEW ORDER HAS BEEN PLACED FOR: " + req.body.user_company + ". 

 The Information the client has entered is as follows:

 Phone Number " + req.body.user_phoneNumber + "

 Company: " + req.body.user_company + "

 Location: " + req.body.user_location + "

 Branch Number " + req.body.user_BranchNumber + "

 PO Number: " + req.body.user_ponumber + "

 Products Ordered: 
" + PRODUCTS + "
 Order total is: $" + req.body.priceTotal + "

 " // plain text body
                     
                  });
                  dropTable(req, res)
                conn.close(function () {
                    console.log('dropped table');
                });
            });
        });
        console.log(PRODUCTS)

    console.log("list of produtcs adrer email",PRODUCTS)
    // console.log("Message sent: %s", info1.messageId);
    // Message sent: <[email protected]>
  
    // Preview only available when sending through an Ethereal account
    //console.log("Preview URL: %s", nodemailer.getTestMessageUrl(info1));
    // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
  }
  
  main().catch(console.error);
  
     
})
});
}); 
});

not sure why it stopped working, or what that error really means... thanks for the help in advance.

question from:https://stackoverflow.com/questions/66067557/nodemailer-failing-on-email-send

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...