Nodemailer /发送给出404错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nodemailer /发送给出404错误相关的知识,希望对你有一定的参考价值。
我正在尝试使用nodemailer将邮件从标准网站表单发送到电子邮件地址。我遵循了此tutorial,所有内容都在本地服务器上运行。但是,当我将文档上传到托管服务提供商时,出现以下错误:
POSThttp://mydomain.rs/send404(未找到)
未找到
在此服务器上找不到请求的URL /发送。
此外,尝试使用404未找到错误ErrorDocument处理请求。
我有与nodemailer相关的三个文件,它们是:
app.js
var http = require('http');
var express = require('express');
var nodemailer = require("nodemailer");
var bodyParser = require('body-parser');
var path = require('path');
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
));
app.use(express.static(__dirname + '/'));
// Home page
app.get('/', function (req, res)
res.sendFile('index.html');
//console.log
console.log('NodeMailer reading console log...' + req.url);
);
// 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;
// Sending Emails with SMTP, Configuring SMTP settings
var smtpTransport = nodemailer.createTransport("SMTP",
host: "mail.mydomain.rs", // hostname
secureConnection: true, // use SSL
port: 465, // port for secure SMTP
auth:
user: 'messages@mydomain.rs',
pass: 'password'
,
proxy: 'http://mydomain.rs:' + port
);
var mailOptions =
from: "Node Emailer ✔ <messages@mydomain.rs>", // sender address
to: req.body.emailto, // 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("Server is Running on 127.0.0.1:" + port);
);
索引页中与表格有关的部分:
index.html
<form role="form" id="emailForm" method="post">
<div class="form_content">
<h2>KONTAKTIRAJTE NAS</h2>
<p id="msg"></p>
<input type="text" name="ime" placeholder="IME" required="required" />
<input type="tel" name="telefon" placeholder="TELEFON" />
<p class="mini_text">
Otvoreni od 8h - 17h
<br> Zatvoreni vikendom osim za posebne usluge
</p>
<input type="email" name="emailto" value="myactualemail@gmail.com" style="visibility: hidden; position: absolute;">
<input type="email" name="email" placeholder="EMAIL" required="required" />
<textarea name="description" placeholder="PORUKA" required="required"></textarea>
<button id="send" type="button">POŠALJI</button>
</div>
</form>
和package.json
"name": "speednodemailers",
"version": "0.0.1",
"description": "NodeJs email form to send email using nodejs",
"dependencies":
"body-parser": "^1.13.3",
"express": "^3.21.2",
"node-mailer": "^0.1.1",
"nodemailer": "^0.7.1"
因此,正如我所提到的,一切都可以在localhost上正常运行,当我将项目上传到托管服务提供商时,就会出现问题。
我缺少上载的步骤吗?还是我忽略的设置?任何帮助都将不胜感激,因为我是后端方面的新手。
谢谢!
答案
尝试此nodemailer tutorial,
也将您的nodemailer更新为最新版本。
以上是关于Nodemailer /发送给出404错误的主要内容,如果未能解决你的问题,请参考以下文章
我收到错误“ 错误:无效登录:535-5.7.8 用户名和密码不被接受。”当我尝试使用 Node JS 中的模块 nodemailer 发送邮件时
Node.js Nodemailer 和 SES - 错误:未定义传输方法