Nodemailer 给出错误请求 400,邮件服务器设置正确

Nodemailer giving Bad Request 400, settings for mailserver are correct

nodemailer 的新手,但我试图让它向我在每次注册时设置的邮件帐户发送电子邮件。我已通过在 outlook 中设置帐户并使用我在 app.js 中编写的 copy/pasted 凭据登录来验证设置是否正确。一切都已检查完毕,但每次我尝试发送电子邮件时,我都会收到 BAD REQUEST 400。我尝试过不使用 SSL 的端口 25 和使用 SSL 的 465。有什么我想念的吗?有什么办法可以记录发生的事情吗?

干杯

CONTROLLER.JS

angular.module('app.InformationModule.controller', [])
.controller('InformationController', ['$scope', 'ajaxUtil', '$routeParams',
function($scope, ajaxUtil, $routeParams){
  $scope.contact=false;
  $scope.policy=false;
  $scope.company=false;
  $scope.jobs=false;
  $scope.coupons=false;

if($routeParams.category === "policy"){
  $scope.policy=true;
}

else if($routeParams.category === "company"){
  $scope.company=true;
}
else if($routeParams.category === "contact"){
  $scope.contact=true;
}
else if($routeParams.category === "jobs"){
  $scope.jobs=true;
}
else if($routeParams.category === "coupons"){
  $scope.coupons=true;
}
else if($routeParams.category === "education"){
  $scope.education=true;
}

    $scope.registration = {
    name : "",
    company : "",
    phone : "",
    address : "",
    city : "",
    state : "",
    zip : ""
    };

    $scope.sendReg = function () {
        ajaxUtil.post("/registration", $scope.registration, $scope, "onRegistration");
    };

    $scope.onRegistration = function(response, error) {
    $scope.registration= {};
    if(error){
      $scope.responseColor = "error";
      $scope.message = "error while trying to register";
    }
    else{
      $scope.responseColor = "success";
      $scope.message = "sucessfully registered";
    }
  };

  ga('send', 'pageview', {
  'title': 'Information page'
  });

}]);   

服务器APP.JS

app.post('/registration', function(req, res){

var transporter = nodemailer.createTransport({
  host: 'mail.server.com',
  port: '465',
  secure: true,
  auth: {
    user: 'account@server.com',
    pass: 'password'
  }
});

var mailOptions = {
  from: 'account@server.com',
  to: 'account@server.com',
  subject: 'subject',
  text: 'New Registration:'
};

transporter.sendMail(mailOptions, function(error, info){
    if(error) {
      res.send(400);
    } else {
      res.send(200);
    }
});

});

想通了。

IP/Hostname 发生冲突,因为我使用的是自签名证书。

需要添加 TLS 选项并将 rejectUnauthorized 设置为 false。到服务器 APP.JS.

中的传输器
var transporter = nodemailer.createTransport({
  host: 'mail.server.com',
  port: '465',
  secure: true,
  auth: {
    user: 'account@server.com',
    pass: 'password'
  },
  tls: {
    rejectUnauthorized: false
   }
});