【问题标题】:{ "code": "ECONNECTION", "command": "CONN" } in nodemailer{ "code": "ECONNECTION", "command": "CONN" } 在 nodemailer
【发布时间】:2019-07-24 10:21:37
【问题描述】:

我创建了 firebase HTTP 云函数,用于在生成的链接上发送 GET 请求时发送邮件, 我正在使用 nodemailer 发送简单的邮件。 我正在使用从 Google OAuth 2.0 Playground 生成的客户端 ID、客户端密码和刷新令牌,并生成访问令牌来验证 Gmail。

    const functions = require('firebase-functions');
    const user_name     = 'XXXXXXXX@gmail.com';
    const refresh_token = '1/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
    let access_token  = '';
    const client_id     = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
    const client_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXX';

    const email_to = 'YYYYYYYYYYYYYYY@gmail.com';

    const nodemailer = require('nodemailer');

    let transporter = nodemailer
        .createTransport({
            service: 'Gmail',
            auth: {
                type: 'OAuth2',
                clientId: client_id,
                clientSecret: client_secret
            }
        });
    transporter.on('token', token => {
        console.log('A new access token was generated');
        console.log('User: %s', token.user);
        access_token = token.accessToken
        console.log('Access Token: %s', token.accessToken);
        console.log('Expires: %s', new Date(token.expires));
    });
    // setup e-mail data with unicode symbols
    let mailOptions = {
        from    : user_name, // sender address
        to      : email_to, // list of receivers
        subject : 'Hello ✔', // Subject line
        text    : 'Hello world ?', // plaintext body
        html    : '<b>Hello world ?</b>', // html body

        auth: {
            user         : user_name,
            refreshToken : refresh_token,
            accessToken  : access_token,
            expires      : 1494388182480
        }
    };

    // send mail with defined transport object
    exports.mail = functions.https.onRequest((req, res) => {
        transporter.sendMail(mailOptions).then( r => {
            return res.send(error);
        }).catch(e =>{
            return res.send(e);
        });
    });

我不断收到错误: { “代码”:“连接”, “命令”:“CONN” } 从 Postman 发送 GET 请求时

我发现transporter.on('token', ()=&gt;{}) 什么都没做, 它完全被我的代码转义了。

那么如何生成access_token呢?

【问题讨论】:

    标签: node.js oauth-2.0 firebase-authentication google-cloud-functions nodemailer


    【解决方案1】:

    显然,nodemailer 在 firebase 云功能中不起作用。

    当我使用 express 在本地运行时,它起作用了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-06-22
      • 1970-01-01
      • 2019-02-10
      • 2018-04-07
      • 2022-12-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多