Nodemailer Error Can't Fix

A. Hickman picture A. Hickman · Feb 4, 2017 · Viewed 11k times · Source

I have a very simple application, just starting to get my hands dirty with nodemailer. When I run the app I get errors in the module itself.

app.js:

const nodemailer = require('nodemailer');

const transporter = nodemailer.createTransport('smtps://me%40gmail.com:[email protected]');


var mailOptions = {
    from:    '"Me" <[email protected]>', // sender address
    to:      '[email protected], [email protected]', // list of receivers
    subject: 'Hello dude', // Subject line
    text:    'Test email with text', // plaintext body
    html:    "Testing 1..2..7" // html body
};

// send mail with defined transport object
transporter.sendMail(mailOptions, function (error, info) {
    if (error) {
        return console.log(error);
    }
    console.log('Message sent: ' + info.response);
});

And I get this error:

C:\Users\Andrew\desktop\messy4\node_modules\nodemailer\lib\mailer\index.js:31
            compile: [(...args) => this._convertDataImages(...args)],
                       ^^^

SyntaxError: Unexpected token ...
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:387:25)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (C:\Users\Andrew\desktop\messy4\node_modules\nodemailer\lib\nodemailer.js:3:16)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)

Really not sure what's happenning here.

Answer

ThisClark picture ThisClark · Feb 4, 2017

Node.js version 6+ is required. Check your Node version with the following command:

node --version

If you are not at least 6+ then you must upgrade.

You may receive another error message instructing you to login to your account. In that case, go to your email inbox and you will see a message from Google with a link to a page for setting up less secure app permissions.