缺少“PLAIN”的凭据nodemailer [英] Missing credentials for "PLAIN" nodemailer

查看:760
本文介绍了缺少“PLAIN”的凭据nodemailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在联系表单中使用nodemailer来接收反馈并将其直接发送到电子邮件中。这是下面的表格。

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.

<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: 'user@gmail.com',
        password: 'password'
    }
});
var mailOptions = {
    from: req.body.name + '&lt;' + req.body.email + '&gt;',
    to: 'bantspl@gmail.com',
    subject: 'Plbants Feedback',
    text: req.body.feedback 
};
transporter.sendMail(mailOptions,(err,res)=>{
    if(err){
        console.log(err);
    }
    else {

    }
});

我收到错误缺少PLAIN的凭据。感谢非常感谢,非常感谢。

I'm getting the error Missing credentials for "PLAIN". Any help is appreciated, thank you very much.

推荐答案

我能够通过使用数字3来解决这个问题,设置3LO身份验证,来自nodemailer文档的示例(链接: https://nodemailer.com/smtp/oauth2/)。我的代码如下所示:

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:

let transporter = nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
        type: 'OAuth2',
        user: 'user@example.com',
        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.

要获取clientId,clientSecret,refreshToken和accessToken,我只是观看了此视频 https://www.youtube.com/watch?v=JJ44WA_eV8E

To get the clientId, clientSecret, refreshToken, and accessToken, I just watched this video https://www.youtube.com/watch?v=JJ44WA_eV8E .

我不知道这对你是否仍然有用。

I don't know if this is still helpful to you tho.

这篇关于缺少“PLAIN”的凭据nodemailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆