Answer the question
In order to leave comments, you need to log in
How to send emails from the site?
The problem is that I can't send a letter from a site that is running a production version, but a letter is sent in the development version. I already created a topic before about this. But now, new circumstances.
Here are the logs, but I did not open any of them in terms of a solution, These are the nginx
logs server: alexandra.proto-dev.ru, request: "GET / HTTP/1.1", upstream: " localhost ", host: "alexandra.proto-dev.ru"
2019/09/02 13:11:49 [error] 20745#20745: *21071 upstream prematurely closed connection while reading response header from upstream, client: 77.222.105.17, server: alexandra.proto-dev.ru, request: "POST /send-email HTTP/1.1", upstream: "", host: "alexandra.proto-dev.ru", referrer: " alexandra.proto-dev.ru "
2019/09/02 13:15:02 [error] 20745#20745: *21085 upstream prematurely closed connection while reading response header from upstream, client: 77.222.105.17, server: alexandra.proto-dev.ru, request: "POST /send-email HTTP/1.1", upstream: " 127.0.0.1:3000/send-email ", host: "alexandra.proto-dev.ru", referrer: " alexandra.proto-dev.ru "
2019/09/02 13:26:14 [error] 20745#20745: *21128 upstream prematurely closed connection while reading response header from upstream , client: 77.222.105.17, server: alexandra.proto-dev.ru, request: "POST /send-email HTTP/1.1", upstream: " 127.0.0.1:3000/send-email ", host: "alexandra.proto-dev.ru", referrer: "alexandra.proto-dev.ru "
2019/09/02 13:53:18 [error] 20745#20745: *21153 upstream prematurely closed connection while reading response header from upstream, client: 77.222.105.17, server: alexandra.proto- dev.ru, request: "POST /send-email HTTP/1.1", upstream: " 127.0.0.1:3000/send-email ", host: "alexandra.proto-dev.ru", referrer: " alexandra.proto- dev.ru "
2019/09/02 13:53:35 [notice] 23002#23002: signal process started
2019/09/02 13:54:26 [error] 23003#23003: *21183 upstream prematurely closed connection while reading response header from upstream, client: 77.222.105.17, server: alexandra.proto-dev.ru, request: "POST /send-email HTTP/1.1", upstream: " 127.0.0.1:3000/send-email", host: "alexandra.proto-dev.ru", referrer: " alexandra.proto-dev.ru "
2019/09/02 14:00:45 [error] 23003#23003: *21208 upstream prematurely closed connection while reading response header from upstream, client: 77.222.105.17, server: alexandra.proto-dev.ru, request: "POST /send-email HTTP/1.1", upstream: " 127.0.0.1:3000/send-email ", host: "alexandra.proto-dev.ru", referrer: " alexandra.proto-dev.ru "
2019/09/02 14:04:01 [notice] 23361#23361: signal process started
2019/09/02 14:04: 32 [error] 23362#23362: *21228 upstream prematurely closed connection while reading response header from upstream, client: 77.222.105.17, server: alexandra.proto-dev.ru, request: "POST /send-email HTTP/1.1", upstream: "127.0.0.1:3000/send-email ", host: "alexandra.proto-dev.ru", referrer: " alexandra.proto-dev.ru "
Here is the container config
# Настройка сервера
server {
listen 80;
root /var/www/alexandra.proto-dev.ru;
index index.html;
server_name alexandra.proto-dev.ru;
location ~* \.(?:ico|gif|jpe?g|png)$ {
expires 7d;
add_header Vary Accept-Encoding;
access_log off;
}
location / {
client_max_body_size 100m;
proxy_send_timeout 180s;
proxy_read_timeout 180s;
proxy_pass http://localhost:3000;
}
location /nginx/ {
root /var/www/;
autoindex off;
}
location ~ /\. {
deny all;
}
}
const fs = require('fs');
const next = require('next');
const express = require('express');
const multer = require('multer');
const nodemailer = require("nodemailer");
const upload = multer({ dest: 'uploads/' });
const port = parseInt(process.env.PORT, 10) || 3000;
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app
.prepare()
.then(() => {
const server = express();
server.get('/', (req, res) => {
const actualPage = '/index';
app.render(req, res, actualPage);
});
server.post('/send-email', upload.single('file'), (req, res, next) => {
const message = {
to: `[email protected]`,
subject: `Форма отправлена с сайта alexandra.proto-dev.ru`,
text: `Клиент отправил контактную информацию
Имя: ${req.body.name}
Поятовый ящик: ${req.body.email}
Сообщение: ${req.body.message}`,
attachments: [
{
filename: `${req.file.originalname}`,
content: fs.createReadStream(req.file.path),
},
]
};
const transporter = nodemailer.createTransport(
{
host: 'smtp.mail.ru',
port: 465 ,
secure: true,
auth: {
user: '[email protected]',
pass: 'xxx'
}
},
{
from: `Mailer test [email protected]`
}
);
transporter.sendMail(message, (err, info) => {
if (err) {
res.status(500).send('Email Send Error');
}
res.status(200).send('Email Send Successfully');
});
});
server.get('*', (req, res) => {
return handle(req, res)
});
const listenCallback = err => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`)
};
dev ?
server.listen(port, listenCallback) :
server.listen(port, 'localhost', listenCallback);
})
.catch(ex => {
console.error(ex.stack);
process.exit(1);
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question