Error sending mail using Nodemailer

I create a project and follow all the steps written in response to Nodemailer / Gmail. What is an update token and how can I get it? But I am wrong.

I am using the following code:

var smtpTransport = nodemailer.createTransport("SMTP", { service: "Gmail", connectionTimeout : "7000", greetingTimeout : "7000", auth: { XOAuth2: { user: "", clientId: "", clientSecret: "", refreshToken: "" } } }); var mailOptions = { from: "", to:usersEmailId, subject: 'subject', html: 'string Of Html' } smtpTransport.sendMail(mailOptions, function(error, response){ if(error){ console.log(error); }else{ console.log("Message sent: " + response.message); } smtpTransport.close(); }); 

Getting the following error

 { [Error: Connection timeout] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', stage: 'init' } { [Error: Connection timeout] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', stage: 'init' } { [XOAUTH2Error: invalid_client] name: 'XOAUTH2Error', stage: 'auth' } { [XOAUTH2Error: invalid_client] name: 'XOAUTH2Error', stage: 'auth' } 

and my second question is how to send an attachment. I have only the file name and file url .

+3
email gmail-api nodemailer
Mar 04 '16 at 11:14
source share
2 answers

Use this because the path in the nodemailer document is wrong. this is a problem in nodemailer use filepath, it works

 attachments : [ { // file on disk as an attachment filename: 'name Of File',, filePath : 'url of file' // stream this file }, ], alternatives : [ { // file on disk as an attachment filename: 'name Of File', filePath : 'url of file' // stream this file }, ], 
+1
Mar 09 '16 at 5:58
source share

I wrote a wrapper module around Nodemailer / nodemailer-smtp-transport / xoauth2.

Take a look at Gist if it helps:

 // USAGE // response is coming (in my case) from REDIS var constants = { stmp_host: 'smtp-relay.gmail.com', user: resp.SUPORTE_MAIL, user_name: resp.SUPORTE_NAME, clientId: resp.OAUTH_CLIENT_ID, clientSecret: resp.OAUTH_CLIENT_SECRET, refreshToken: resp.OAUTH_REFRESH_TOKEN }; var Mailer = require('./my-mailer.js'); var mailer = new Mailer(constants); mailer.createTransporter().then(function(){ var send_info = { subject: 'A test!', html: 'some<br>formatted <strong>text</strong>', to_name: 'Some Name', to_email: 'some@gmail.com' }; return mailer.getMailObject(send_info); }).then(function(mail_obj){ mailer.sendMail(mail_obj).then(function(info) { console.info('sent to: ', info); process.exit(); }).catch(function(err) { console.info('error: ', err); }); }); 
+1
Mar 04 '16 at 14:57
source share