简体   繁体   中英

nodemailer email login invalid

{ [Error: Invalid login: 535 5.0.0 Authentication Failed] code: 'EAUTH', response: '535 5.0.0 Authentication Failed',
responseCode: 535 }

It keeps giving me this error, tried several times with different tutorials and still not working....

Also I know it will be hard to access to gmail's authentication and on top of that my gmail has two steps secure validation, so I decided to use Hotmail instead...

Here is code for my index.html

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script><script>
        <script>
            $(document).ready(function(){
                    var from,name,email,subject,text;
                    $("#submit").click(function(){
                            name=$("#name").val();
                            email=$("#email").val();
                            subject=$('#subject').val();`enter code here`
                            text=$("#message").val();
                            $("#messages").text("Sending E-mail...Please wait");
                            $.get("http://localhost:8000/send",{name:name,email:email,subject:subject,text:text},function(data){
                            if(data=="sent")
                            {
                                    $("#messages").empty().html("

            Email is been sent at "+to+" . Please check inbox !

            ");
                            }

            });
                    });
            });
        </script>

below is my server.js code

var express = require('express');
var path = require('path');
var app = express();
var nodemailer = require("nodemailer");

app.use(express.static('assets'));

var smtpTransport = nodemailer.createTransport({
  service: 'Hotmail',
  auth: {
    user: 'myemail.com',
    pass: 'something'
  }
});

app.get('/', function(req, res){
  res.sendFile(__dirname + '/index.html');
});

app.get('/send', function(req, res){

  var mailOptions={
       from: "ME <my@hotmail.com>",
       name : req.query.name,
       To: req.query.email,
       subject: req.query.subject,
       text: req.query.message
   };

   console.log(mailOptions);
    smtpTransport.sendMail(mailOptions, function(error, response){
     if(error){
            console.log(error);
        res.end("error");
     }else{
            console.log("Message sent: " + response.message);
        res.end("sent");
      }
  });
});

app.listen(8000, function(){`enter code here`
});

Hotmail might block connections from unexpected geographical locations, check your account security overview to see if you need to confirm any login attempts.

Additionally, if you use 2-factor auth for Hotmail then you need application specific password for Nodemailer, you can't use your account password in this case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM