Javascript 缺少“PLAIN”节点邮件程序的凭据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/48854066/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Missing credentials for "PLAIN" nodemailer
提问by igolo
I'm trying to use nodemailer in my contact form to receive feedback and send them directly to an email. This is the form below.
我正在尝试在我的联系表单中使用 nodemailer 来接收反馈并将它们直接发送到电子邮件。这是下面的表格。
<form method="post" action="/contact">
<label for="name">Name:</label>
<input type="text" name="name" placeholder="Enter Your Name" required><br>
<label for="email">Email:</label>
<input type="email" name="email" placeholder="Enter Your Email" required><br>
<label for="feedback">Feedback:</label>
<textarea name="feedback" placeholder="Enter Feedback Here"></textarea><br>
<input type="submit" name="sumbit" value="Submit">
</form>
This is what the request in the server side looks like
这是服务器端请求的样子
app.post('/contact',(req,res)=>{
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
password: 'password'
}
});
var mailOptions = {
from: req.body.name + '<' + req.body.email + '>',
to: '[email protected]',
subject: 'Plbants Feedback',
text: req.body.feedback
};
transporter.sendMail(mailOptions,(err,res)=>{
if(err){
console.log(err);
}
else {
}
});
I'm getting the error Missing credentials for "PLAIN". Any help is appreciated, thank you very much.
我收到错误Missing credentials for "PLAIN"。任何帮助表示赞赏,非常感谢。
回答by thegreathypocrite
I was able to solve this problem by using number 3, Set up 3LO authentication, example from the nodemailer documentation (link: https://nodemailer.com/smtp/oauth2/). My code looks like this:
我能够通过使用编号 3,设置 3LO 身份验证,来自 nodemailer 文档的示例(链接:https://nodemailer.com/smtp/oauth2/ )来解决此问题。我的代码如下所示:
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
type: 'OAuth2',
user: '[email protected]',
clientId: '000000000000-xxx0.apps.googleusercontent.com',
clientSecret: 'XxxxxXXxX0xxxxxxxx0XXxX0',
refreshToken: '1/XXxXxsss-xxxXXXXXxXxx0XXXxxXXx0x00xxx',
accessToken: 'ya29.Xx_XX0xxxxx-xX0X0XxXXxXxXXXxX0x'
}
});
If you looked at the example in the link that I stated above, you can see there that there is a 'expires' property but in my code i didn't include it and it still works fine.
如果您查看我上面提到的链接中的示例,您会看到那里有一个“过期”属性,但在我的代码中我没有包含它,它仍然可以正常工作。
To get the clientId, clientSecret, refreshToken, and accessToken, I just watched this video https://www.youtube.com/watch?v=JJ44WA_eV8E.
为了获取 clientId、clientSecret、refreshToken 和 accessToken,我刚刚观看了此视频https://www.youtube.com/watch?v=JJ44WA_eV8E。
I don't know if this is still helpful to you tho.
我不知道这对你是否仍然有帮助。
回答by Jeffrey Roshan
Gmail / Google app email service requires OAuth2 for authentication. PLAIN text password will require disabling security features manually on the google account.
Gmail / Google 应用电子邮件服务需要 OAuth2 进行身份验证。纯文本密码需要在 google 帐户上手动禁用安全功能。
To use OAuth2 in Nodemailer, refer: https://nodemailer.com/smtp/oauth2/
要在 Nodemailer 中使用 OAuth2,请参考:https://nodemailer.com/smtp/oauth2/
Sample code:
示例代码:
var email_smtp = nodemailer.createTransport({
host: "smtp.gmail.com",
auth: {
type: "OAuth2",
user: "[email protected]",
clientId: "CLIENT_ID_HERE",
clientSecret: "CLIENT_SECRET_HERE",
refreshToken: "REFRESH_TOKEN_HERE"
}
});
And if you still want to use just plain text password, disable secure login on your google account and use as follows:
如果您仍然只想使用纯文本密码,请在您的 google 帐户上禁用安全登录并使用如下:
var email_smtp = nodemailer.createTransport({
host: "smtp.gmail.com",
auth: {
type: "login", // default
user: "[email protected]",
pass: "PASSWORD_HERE"
}
});
回答by Victor Fazer
You have
你有
auth: {
user: '[email protected]',
password: 'password'
}
But you should write this
但是你应该写这个
auth: {
user: '[email protected]',
pass: 'password'
}
Just rename password to pass.
只需重命名密码即可通过。

