1

传输中的电子邮件加密 (TLS),我该如何更改我收到未定义的电子邮件?

我正在使用 nodemailer,一切正常,但我收到一封没有内容的电子邮件,我对将表单链接到 app.js 感到困惑,因此它将信息发送到我的电子邮件。

感谢社区的任何建议!

很有趣,因为我确实收到了电子邮件,在几秒钟内,我对它的回复速度感到惊讶。

/*
 * Author: Cesar Diaz
 * Date: 2-25-2016
 * Website: help me keep my home
 * App Name: Node Emailer
 * Description: NodeJs script to send emails
 */
var http = require('http');
var express = require('express');
var nodemailer = require("nodemailer");
var bodyParser = require('body-parser')
var app = express();
var port = Number(process.env.PORT || 5000);
app.use(bodyParser.json()); // to support JSON-encoded bodies
app.use(bodyParser.urlencoded({
  extended: true
}));

// Home page
app.get('/', function(req, res) {
  res.sendfile('index.html');
});

// sending mail function
app.post('/send', function(req, res) {
  if (req.body.email == "" || req.body.subject == "") {
    res.send("Error: Email & Subject should not blank");
    return false;
  }

  var subject = "Email from " + req.body.name + " " + req.body.lastname;
  var description = req.body.name + " " + req.body.lastname + " " +       req.body.phone + " " + req.body.email + " " + req.body.state + " " +     req.body.lender + " " + req.body.property;

  // Sending Email Without SMTP
  nodemailer.mail({
    from: "Node Emailer ✔ <no-reply@iamrohit.in>", // sender address
    to: req.body.email, // list of receivers
    subject: req.body.subject + " ✔", // Subject line
    //text: "Hello world ✔", // plaintext body
    html: "<b>" + req.body.description + "</b>" // html body
  });
  res.send("Email has been sent successfully");

  // Sending Emails with SMTP, Configuring SMTP settings

  var smtpTransport = nodemailer.createTransport("SMTP", {
    host: "smtp.gmail.com", // hostname
    secureConnection: true, // use SSL
    port: 465, // port for secure SMTP
    auth: {
      user: '//removed',
      pass: "['removed']"
    }
  });
  var mailOptions = {
    from: "Node Emailer ✔ <no-reply@iamrohit.in>", // sender address
    to: req.body.email, // list of receivers
    subject: req.body.subject + " ✔", // Subject line
    //text: "Hello world ✔", // plaintext body
    html: "<b>" + req.body.description + "</b>" // html body
  }
  smtpTransport.sendMail(mailOptions, function(error, response) {
    if (error) {
      res.send("Email could not sent due to error: " + error);
    } else {
      res.send("Email has been sent successfully");
    }
  });
});

// Starting server
var server = http.createServer(app).listen(port, function() {
  console.log("Listening on " + port);
});
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Send email in nodejs</title>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</head>

<body>
  <div class="panel panel-primary" style="width:50%;margin:0 auto; margin-top:10%">
    <div class="panel-heading">
      <h3>Help is here!</h3>
    </div>
    <div class="panel-body" style="height:40%; text-align:center;">
      <p class="bg-info" id="msg"></p>
      <form class="form-horizontal" role="form" id="emailForm" method="post">


        <div class="form-group">
          <label class="control-label col-sm-2" for="name">
            First name
          </label>
          <div class="col-sm-10">
            <input type="name" class="form-control" name="name" placeholder="Enter first name" required="required">
          </div>
        </div>


        <div class="form-group ">
          <label class="control-label col-sm-2" for="name1">
            Last name
          </label>
          <div class="col-sm-10">
            <input type="last-name" class="form-control" name="last-name" placeholder="Enter last name" required="required">
          </div>
        </div>


        <div class="form-group ">
          <label class="control-label col-sm-2" for="tel">
            Telephone
          </label>
          <div class="col-sm-10">
            <input type="phone" class="form-control" name="phone" placeholder="Enter phone number" required="required">
          </div>
        </div>


        <div class="form-group">
          <label class="control-label col-sm-2" for="email">Email:</label>
          <div class="col-sm-10">
            <input type="email" class="form-control" name="email" placeholder="Enter email" required="required">
          </div>
        </div>


        <div class="form-group ">
          <label class="control-label col-sm-2" for="state">
            What state are you in?
          </label>
          <div class="col-sm-10">
            <select class="form-control">
              <option>Alabama</option>
              <option>Alaska</option>
              <option>Arizona</option>
              <option>Arkansas</option>
              <option>California</option>
              <option>Colorado</option>
              <option>Connecticut</option>
              <option>Delaware</option>
              <option>Florida</option>
              <option>Georgia</option>
              <option>Hawaii</option>
              <option>Idaho</option>
              <option>Illinois Indiana</option>
              <option>Iowa</option>
              <option>Kansas</option>
              <option>Kentucky</option>
              <option>Louisiana</option>
              <option>Maine</option>
              <option>Maryland</option>
              <option>Massachusetts</option>
              <option>Michigan</option>
              <option>Minnesota</option>
              <option>Mississippi</option>
              <option>Missouri</option>
              <option>Montana Nebraska</option>
              <option>Nevada</option>
              <option>New Hampshire</option>
              <option>New Jersey</option>
              <option>New Mexico</option>
              <option>New York</option>
              <option>North Carolina</option>
              <option>North Dakota</option>
              <option>Ohio</option>
              <option>Oklahoma</option>
              <option>Oregon</option>
              <option>Pennsylvania Rhode Island</option>
              <option>South Carolina</option>
              <option>South Dakota</option>
              <option>Tennessee</option>
              <option>Texas</option>
              <option>Utah</option>
              <option>Vermont</option>
              <option>Virginia</option>
              <option>Washington</option>
              <option>West Virginia</option>
              <option>Wisconsin</option>
              <option>Wyoming</option>
            </select>
          </div>
        </div>


        <div class="form-group ">
          <label class="control-label col-sm-2" for="owe">
            How much do you owe on your house?
          </label>
          <div class="col-sm-10">
            <select class="form-control">
              <option>Select one</option>
              <option>owe less than $75,000 on home</option>
              <option>owe between $75,000 to 100,000</option>
              <option>owe between $100,000 to $200,000</option>
              <option>owe between $300,000 to $400,000</option>
              <option>owe between $400,000 to $500,000</option>
              <option>owe more than $500,000 on home</option>
            </select>
          </div>
        </div>


        <div class="form-group ">
          <label class="control-label col-sm-2" for="lender">
            Who is your lender?
          </label>
          <div class="col-sm-10">
            <input class="form-control" id="lender" name="lender" type="text" />
          </div>
        </div>


        <div class="form-group ">
          <label class="control-label requiredField" for="foreclose-date">
            Is there a foreclosure sales auction date set?
            <label class="radio-inline">
              <input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1">Yes
            </label>
            <label class="radio-inline">
              <input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2">No
            </label>
          </label>
        </div>


        <div class="form-group ">
          <label class="control-label col-sm-2" for="property">
            Property address
          </label>
          <div class="col-sm-10">
            <input class="form-control" id="property" name="property" type="text" />
          </div>
        </div>


        <div class="form-group">
          <div class="col-sm-offset-2 col-sm-10">
            <button id="send" class="btn btn-primary btn-lg" type="button">
              <span class="glyphicon glyphicon-send"></span> Send
            </button>
          </div>
        </div>
      </form>
    </div>
  </div>


  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
  <script>
    $(function() {
      var fullUrl = location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '');
      $("#send").click(function() {
        var formData = $("#emailForm").serialize();
        $("#msg").text("Email sending Please wait..");
        $.ajax({
          url: fullUrl + '/send',
          type: 'POST',
          data: formData,
          success: function(result) {
            $("#msg").empty().text(result);
          },
          error: function(e) {
            $("#msg").empty().text("There is some error to send email, Error code:" + e.status + ", Error message:" + e.statusText);
          },
          dataType: "html",
          timeout: 60000
        });
      });
    });
  </script>
</body>

</html>

4

0 回答 0