I want to test my Node.js + Express + Nodemailer app.

Can I generate an error?

smtpTransport.sendMail(mailOptions, function(error, response){
    if(error){
        console.log(error);

        res.contentType('json');
        res.writeHead(500, { 'Content-Type': 'application/json'});
        res.write(JSON.stringify({ success: false, message: error }));
        res.end();
    }else{
        console.log("Message sent: " + response.message);

        res.contentType('json');
        res.writeHead(200, { 'Content-Type': 'application/json'});
        res.write(JSON.stringify({ success: true, message: response.message }));
        res.end();
    }

});
有帮助吗?

解决方案

It all depends on what type of error you are trying to receive.

Here are a couple of suggestions:

  1. Enter an incorrect password in the mailOptions object for the account that will be sending the emails. This will produce an Authorization error of some sort.

  2. Drop your internet connection before this code is executed. You can use node-inspector to insert a breakpoint in the server code to stop execution and disconnect from the network before resuming.


To install node-inspector:

npm install -g node-inspector

then run

node-debug app.js


Hope this helps!

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top