如何解决使用Nginx设置Nodemailer
我在Nginx服务器上设置Nodemailer时遇到问题。我是新手,这真的让我感到困惑。 这是我的节点 app.js 文件:
const express = require("express");
const bodyParser = require("body-parser");
const path = require("path");
const nodemailer = require("nodemailer");
const port = process.env.PORT || 5000;
const ip = process.env.IP || "51.195.91.42";
const app = express();
//body parser
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
//public folder
app.use(express.static(path.join(__dirname,"build")));
const confirm = {
info: "Wiadomość wysłana poprawnie",};
const confirm2 = {
info: "Wystąpił błąd",};
app.get("/",(req,res) => {
res.sendFile(path.join(__dirname,"build","index.html"));
});
app.post("/send",res) => {
const output = `
<p>Nowa wiadomość:</p>
<h3>Dane kontaktowe</h3>
<ul>
<li>Imię: ${req.body.name}</li>
<li>Mail: ${req.body.mail}</li>
<li>Wiadomość: ${req.body.message}</li>
</ul>
`;
async function main() {
let transporter = nodemailer.createTransport({
host: "ssl0.ovh.net",port: 465,secure: true,auth: {
user: "example@example.pl",pass: "example",},tls: {
rejectUnauthorized: false,});
// send mail with defined transport object
await transporter
.sendMail({
from: `${req.body.name} ? <${req.body.mail}>`,// sender address
to: "example@example.pl",// list of receivers
subject: `${req.body.name}`,// Subject line
html: output,// html body
})
.then(() => {
console.log(`Message from ${req.body.mail} has been sent!`);
res.send(confirm);
})
.catch(() => {
console.log(`Unable to send!`);
res.send(confirm2);
});
}
main().catch(console.error);
});
app.listen(port,ip);
这是我在nginx中的朋友:
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
465/tcp ALLOW Anywhere
25 ALLOW Anywhere
587 ALLOW Anywhere
22/tcp (v6) ALLOW Anywhere (v6)
80/tcp (v6) ALLOW Anywhere (v6)
443/tcp (v6) ALLOW Anywhere (v6)
465/tcp (v6) ALLOW Anywhere (v6)
25 (v6) ALLOW Anywhere (v6)
587 (v6) ALLOW Anywhere (v6)
我已经发现我需要更改/etc/nginx/nginx.conf文件中的邮件配置,但是不知道如何执行。现在,任何在我的网站上提交表单的尝试都将导致请求拖延,如果没有适当的配置,这将是期望。谢谢您的任何建议。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。