A
A
Andrey Okhotnikov2018-05-14 20:09:34
JavaScript
Andrey Okhotnikov, 2018-05-14 20:09:34

How to send email through nodemailer?

The letter from the form is not sent through nodemailer from the hosting. From the locale, everything is sent as it should. Here is the code. Tell me what's wrong?

const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const nodemailer = require('nodemailer');
const app = express();



// Body Parser Middleware
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());

var staticSiteOptions = {
  portnum: 3000, 
  maxAge: 1000 * 60 * 15 
};

app.post('/send', (req, res) => {
  const output = `
    <p>You have a new contact request</p>
    <h3>Contact Details</h3>
    <ul>  
      <li>Name: ${req.body.name}</li>
      <li>Email: ${req.body.email}</li>
    </ul>
    <h3>Message</h3>
    <p>${req.body.desc}</p>
  `;

  // create reusable transporter object using the default SMTP transport
  let transporter = nodemailer.createTransport({
    service: "Gmail",
    auth: {
        user: "Тут мой емейл",
        pass: "Тут пароль ;)"
    }
})

  // setup email data with unicode symbols
  let mailOptions = {
    from: "Andrey Okhotnikov <[email protected]>", // sender address
    to: "ТУТ МОЙ ЕМЕЙЛ", // list of receivers
    subject: "", // Subject line
    html: output
}

  // send mail with defined transport object
  transporter.sendMail(mailOptions, (error, info) => {
      if (error) {
          return console.log(error);
      }
      console.log('Message sent: %s', info.messageId);   
      console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));

      res.sendStatus(200)
  });
});
app.use(express.static(
  path.join(__dirname, 'public'),
  staticSiteOptions
)).listen(staticSiteOptions.portnum);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Ermakhan Sabyrzhanov, 2018-06-07
@ErmaKing

I think you can handle POST requests))
https://www.instagram.com/p/BjXlzLVH2PQ/?utm_sourc...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question