-1

I am using nodemail npm package.

I configured the options like this:

function feedback(req, res, next){
    console.log('feed back given....', req.body);
    smtpTrans = nodemailer.createTransport('SMTP', {
        service: 'Gmail',
        host: 'smtp.gmail.com',
        port: 587,
        secure: false,
        ignoreTLS: false,
        tls: { rejectUnauthorized: true },
        debug: false,
        auth: {
            user: "xxxxxx@gmail.com",
            pass: "xxxxxx" 
        }
    });

    //Mail options
    mailOpts = {
        from: from: req.body.email,
        to: 'xxxxxx@gmail.com',
        subject: 'EMAIL FROM Rsc-student: ' + req.body.subject,
        text: req.body.message
    };

    smtpTrans.sendMail(mailOpts, function (error, response) {
      //Email not sent
      if (error) {
          res.send(error);
          console.log('error sending mail');
      }
      else {
          res.send(response);
          console.log('success sending mail');
      }
    });
}

If I am not wrong, I configured correctly but still unable to send mail. Its printing the error case

kittu
  • 6,662
  • 21
  • 91
  • 185
  • can u share `error`? – Bhavana Dec 02 '16 at 05:39
  • ```from: from: req.body.email,``` make sure this line is correct! – bharadhwaj Dec 02 '16 at 05:43
  • from: from: req.body.email, change this line to- from: req.body.email – AJS Dec 02 '16 at 05:47
  • @user29 its just printing the console in if condition – kittu Dec 02 '16 at 05:52
  • Do it `console.log("The error is :", error);` – Arpit Kumar Dec 02 '16 at 05:53
  • Print error message using `console.log(error);` – Bhavana Dec 02 '16 at 05:53
  • log error console.log(error) instead of your custom error message console.log('error sending mail'); – AJS Dec 02 '16 at 05:56
  • my bad i didn't print error properly. Now its printing `error sending mail: [Error: Unsupported configuration, downgrade Nodemailer to v0.7.1 to use it]` – kittu Dec 02 '16 at 05:57
  • take look at this link https://github.com/nodemailer/nodemailer#use-the-default-smtp-transport to create transport – AJS Dec 02 '16 at 05:59
  • You can refer this link [Node Mailer Error:“Unsupported configuration, downgrade Nodemailer to v0.7.1 to use it” in localhost][1] [1]: http://stackoverflow.com/questions/34652481/node-mailer-errorunsupported-configuration-downgrade-nodemailer-to-v0-7-1-to – Arpit Kumar Dec 02 '16 at 05:59
  • I downgraded to 7.1 and now its printing `error sending mail: { [Error: 101057795:error:140770FC:SSL routines:SSL23_GET_S ERVER_HELLO:unknown protocol:openssl\ssl\s23_clnt.c:794: ] stage: 'init' }` – kittu Dec 02 '16 at 06:00

2 Answers2

1

Remove extra from: from mailOpts.

Bhavana
  • 1,014
  • 4
  • 17
  • 26
1

Follow this 3 steps:

  1. Login to your Gmail account.

  2. Follow this link allow gmail to send mail over less secure app.

  3. Select on option.

It works for me. I hope it will help you.

Arpit Kumar
  • 2,179
  • 5
  • 28
  • 53