节点邮件不起作用,怎么了
Nodemailer doesn't work, what's wrong?
我在使用Nodemailer时遇到了问题。它适用于本地主机并响应错误消息。这是怎么回事?反应.js代码示例:
import React from 'react'
import styles from './index.css'
export default class Form extends React.Component {
render() {
return (
<form action='/contact' method='post'>
<h2>Contact me</h2>
<input name='name' type='text' placeholder='Name' required />
<input name='location' type='text' placeholder='Location' required />
<input name='email' type='email' placeholder='Email' required />
<textarea name='message' />
<button type='submit'>Send</button>
</form>
);
}
}
这是服务器的一部分.js快递文件:
app.use(middleware);
app.use(webpackHotMiddleware(compiler));
app.get('/', function response(req, res) {
res.write(middleware.fileSystem.readFileSync(path.join(__dirname, '../dist/index.html')));
res.end();
});
app.post('/contact', function (req, res) {
// Setup Nodemailer transport
var mailOpts, smtpTrans;
smtpTrans = nodemailer.createTransport('SMTP', {
service: 'Gmail',
auth: {
user: "some-my-email@gmail.com",
pass: "password-of-thisemail"
}
});
//Mail options
mailOpts = {
from: 'noreply@domain.io>',
to: 'my@domain.io',
subject: 'Website contact form',
text: 'Hello!'
};
smtpTrans.sendMail(mailOpts, function (error, response) {
// Email not sent
if (error) {
res.render('contact', {
err: true, page: 'contact'
})
}
// Email sent
else {
res.render('contact', {
err: false, page: 'contact'
})
}
});
});
Error: No default engine was specified and no extension was provided.
at new View (/home/azat/git/azat-io/node_modules/express/lib/view.js:62:11)
at EventEmitter.render (/home/azat/git/azat-io/node_modules/express/lib/application.js:569:12)
at ServerResponse.render (/home/azat/git/azat-io/node_modules/express/lib/response.js:961:7)
at /home/azat/git/azat-io/scripts/server.js:52:13
at Nodemailer.sendMail (/home/azat/git/azat-io/node_modules/nodemailer/lib/nodemailer.js:265:16)
at /home/azat/git/azat-io/scripts/server.js:50:15
at Layer.handle [as handle_request] (/home/azat/git/azat-io/node_modules/express/lib/router/layer.js:95:5)
at next (/home/azat/git/azat-io/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/home/azat/git/azat-io/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/azat/git/azat-io/node_modules/express/lib/router/layer.js:95:5)
at /home/azat/git/azat-io/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/home/azat/git/azat-io/node_modules/express/lib/router/index.js:330:12)
at next (/home/azat/git/azat-io/node_modules/express/lib/router/index.js:271:10)
at middleware (/home/azat/git/azat-io/node_modules/webpack-hot-middleware/middleware.js:39:48)
at Layer.handle [as handle_request] (/home/azat/git/azat-io/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/home/azat/git/azat-io/node_modules/express/lib/router/index.js:312:13)
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
那么,这段代码有什么问题呢?你能帮帮我吗?
即使nodemailer响应错误,您也应该得到响应。你能试着把nodmailer的部分注释掉,看看你是否得到任何回应。在我看来,这与快递有关。
返回
。的错误是关于Express的.js而不是关于Nodemailer的。
我认为电子邮件没有发送,因为您在电子邮件中使用了原始密码。您必须从您的Google帐户创建新的应用密码才能发送邮件。有关详细信息,请参阅此答案。
"未指定默认引擎,未提供扩展",明确指出您尚未设置默认视图引擎。您可以在此处找到解决方案
在撰写本文时,Google 不再支持安全性较低的应用程序。而且您不能使用您的谷歌帐户密码。
您必须生成新的应用密码。
应用专用密码仅在启用两步验证后才能使用。请按照以下步骤获取应用密码
- 转到 https://myaccount.google.com/security
- 启用 2 因素身份验证
- 为电子邮件创建应用专用密码
- 将该密码(16 个字符)复制到 Nodemailer 身份验证中的 pass 参数中。
const client = nodemailer.createTransport({
service: "Gmail",
auth: {
user: "username@gmail.com",
pass: "Google-App-Password-Without-Spaces"
}
});
client.sendMail(
{
from: "sender",
to: "recipient",
subject: "Sending it from Heroku",
text: "Hey, I'm being sent from the cloud"
}
)
相关文章:
- <text区域>在我的html中包含event.keycode==13之后,wrap就不起作用了
- 不;在课堂上写完后就不起作用了
- 为什么这个代码不起作用?我花了很长时间试图弄清楚这一点
- 我尝试将引导下拉按钮添加到 但下拉菜单不起作用.我该怎么做
- 如果.htaccess文件中只写了一行代码,那么我所有的css和js都不起作用,如何修复它
- JavaScript排序算法不起作用 - 任何明显的我做错了
- 在页面中使用了两次多个图像上传,但第一个正在工作,另一个不起作用
- 角度灯箱不起作用.我做错了什么
- 为什么这个文件上传拖放不起作用,我完全复制了 CodePen 代码
- 在IE9中javascript不起作用,但在打开控制台后它就起作用了
- 我上传了客户's服务器一个js函数不起作用
- Ajax请求三次都不起作用,然后就起作用了
- 我需要一个带有可滚动正文的固定表头.我已经尝试了所有方法,但它似乎不起作用
- I'我试图制作一个chrome查找和替换扩展,但它赢了;不起作用
- 那么getJSon就不起作用了
- Javascript.我一添加math.floor函数,calc()函数就不起作用了
- 节点邮件不起作用,怎么了
- 我的代码不起作用,怎么了
- jQuery prepend()不起作用,怎么了
- 我的Javascript不起作用.我不知道它是不是函数,我是怎么调用它的,我用了什么CSS之类的