尝试通过nodemailer和gmail发送邮件时收到此错误

时间:2017-08-26 18:00:19

标签: node.js gmail nodemailer

'535-5.7.8不接受用户名和密码。了解更多信息,请访问\ n535 5.7.8 https://support.google.com/mail/?p=BadCredentials x66sm1596680lff.64 - gsmtp'我该怎么办? 我正在尝试将电子邮件消息集成到我的应用程序中,即使在通过Gmail API激活并检索client_id和client_secret之后,它仍然无效。

let express = require('express')
let formidable = require('formidable');
let nodemailer = require('nodemailer');
let router = express.Router();
let app = express()

app.use(express.static('dist'));
app.use(express.static('public'));
app.use('/email', router);
router.get('/', handleSayHello);
function handleSayHello(req, res){
    var transporter = nodemailer.createTransport({
        service: "Gmail",
            auth: {
            XOAuth2: {
            user: "mygmail@gmail.com", 

            clientId: "my-generated-OAuthId",
            clientSecret: "my-generated-OAuthSecret",
                }
        }
    })



    var tex_t = `<h1 style = "text-align: center">Hello Joshua</h1>
            <p>How are you doing today</p>  
    `;
    var mailOptions = {
        to : 'anotherUser@soso.com',
        from: 'anotherDifferentUser',
        subject: 'Email Example',
        html: tex_t,
    };
    transporter.sendMail(mailOptions, function(error, info){
        if(error){
            console.log(error);
            res.json({yo: 'error'});
        }else{
            console.log("Message sent: " + info.response);
            res.json({yo: info.response});
        };
    });

}
app.set('port', (process.env.PORT || 3000));
app.listen(app.get("port"), ()=>{
    console.log("App listening at ", app.get('port'));
})

1 个答案:

答案 0 :(得分:0)

最后,伙计们,我搜索了另一封发送电子邮件的电子邮件,甚至无需使用Gmail API并生成client_ids或client_secrets。如果我尝试这个节点制作垃圾差不多2天没有成功,我认为不值得投入任何努力。特别是当他们像电子邮件这样的其他人工作正常时。