1

I'm trying few days to composing mail sending with node.js to gmail with no success :-(

at the beginning of tries I try to send form submittion to my gmail but first I need to understand how do I sent simple mail from body to gmail, perhaps I wrong with syntax or missing something?

actually I uses "heroku" as storage and domain for my site

I tried several plugins (such as mailgun, send grid and more) but the process was too complicated integrate their API's into my site.

actually, I find this article in stack overflow that describe how to send the via nodemailer in relation to my error - URL: node.js nodemailer gmail error

when i copy the answer1 to my code i still receiving error.

I' also pass trough all gmail setup how to turn off security block for less secured apps but i'm still receiving error. all the requires installed over my npm npm install --save

** code **

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

function handleSayHello(req, res) {

var transport = nodemailer.createTransport(smtpTransport({
service: 'gmail',
auth: {
  user: 'myGmail@gmail.com', // my mail
  pass: 'myPassword'
}
}));

var mailOptions = {
from: 'myGmail@gmail.com', // sender address
to: 'myGmail@gmail.com', // list of receivers
subject: 'Email Example' // Subject line
//text: text //, // plaintext body
//html: '<b>Hello world ?</b>' // You can choose to send an HTML body                       instead
};

transport.sendMail(mailOptions, function (error, info) {
if (error) {
  console.log(error);
  res.json({
    yo: 'error',
    err: error
  });
} else {
  console.log('Message sent: ' + info.response);
  res.json({
    yo: info.response,
    info: info
  });
};
});
}

router.get('/', function (req, res, next) {
  handleSayHello(req, res);
});

then i receive this error:
{
"yo": "error",
"err": {
    "code": "EAUTH",
    "response": "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbtx\n534-5.7.14 e8jnXXDaDg-dpFfc3H5ljeaBdmnxbXBDXMh-aXS-mmV4gQsXMSZLiiJHDXuOr3wy-IR2Zp\n534-5.7.14 xnznWLf5y5e3xTbJNlZBNcxBMajM9-SFQGy1MQM2XZRpHgtywuDtEj5iPiP0b2T6Wjbsxg\n534-5.7.14 hgehfzufG6h13qhjQK5IgRPNQsSICRQBtRCl3E1J62wFo8bnvZv4peY5aK55JMpwhSavJb\n534-5.7.14 ho-b9ExGGsXFmw_Er6lc8m3vCmO_Q> Please log in via your web browser and\n534-5.7.14 then try again.\n534-5.7.14  Learn more at\n534 5.7.14  https://support.google.com/mail/answer/78754 t35sm887733qtc.40 - gsmtp",
    "responseCode": 534,
    "command": "AUTH PLAIN"
}

}

if someone can take my code and fix it (if needed) and explain simply what do i need to modify in my google account I'll be great-full so much!

Community
  • 1
  • 1
Haim Sabag
  • 133
  • 2
  • 12

1 Answers1

6

to allow from google/gmail, you should follow these links and allow to less secure apps access: unlock account

and Less secure apps

Let me know if still have issue, I'll check/debug your code.

Pawan Developers
  • 377
  • 4
  • 16
  • Thank you Ravendra! for the quick answer! indeed the mail sent to my Email!!! but still still getting an error while site loaded: you can see this in my site: https://guxcontactus.herokuapp.com/ please tell me how to fix that? thank you in advance! – Haim Sabag Jan 10 '17 at 09:56
  • when I access your url, I didn't get error. Here is respons: ` {"yo":"250 2.0.0 OK 1484043820 16sm1043830qtn.33 - gsmtp","info":{"accepted":["chaimon771@gmail.com"],"rejected":[],"response":"250 2.0.0 OK 1484043820 16sm1043830qtn.33 - gsmtp","envelope":{"from":"chaimon771@gmail.com","to":["chaimon771@gmail.com"]},"messageId":"798444db-a416-0e03-2e5f-cd2bf7193c3b@gmail.com"}}` – Pawan Developers Jan 10 '17 at 10:25
  • Ohh missed that, I just read that now with json viewer, indeed it looks well! thank you so much Dear Ravendra!!! – Haim Sabag Jan 10 '17 at 10:55
  • 2
    Same thing is working on my localhost but on server it gives me error. – Pulkit Aggarwal Jun 28 '18 at 02:34
  • @PulkitAggarwal did you follow steps I shared ? also can you share your error statements so that I can investigate. – Pawan Developers Jun 30 '18 at 04:17
  • @PawanDevelopers thanks for the reply, actually google blocked my server IP that's why it was not working. But now it's working correctly. – Pulkit Aggarwal Jun 30 '18 at 04:47
  • @PulkitAggarwal what did you do to make sure google doesnt reject your server ip address ? – zeah Jan 21 '20 at 00:24