使用Cloud Functions和节点邮件程序的云功能时,创建用户事件的登录无效

时间:2017-05-26 09:28:07

标签: firebase firebase-authentication google-cloud-functions

我正在使用Cloud Functions for Firebase和Nodemailer,并将代码组合在一起以发送欢迎电子邮件。以下是我的代码:

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

const nodemailer = require('nodemailer');
const gmailEmail = encodeURIComponent(functions.config().gmail.email);
const gmailPassword = encodeURIComponent(functions.config().gmail.password);

const mailTransport = nodemailer.createTransport(
`smtps://${gmailEmail}:${gmailPassword}@smtp.gmail.com`);
const APP_NAME = 'Test';

exports.sendWelcomeEmail = functions.auth.user().onCreate(event => {
    const user = event.data; // The Firebase user.
    const email = user.email; // The email of the user.
    const displayName = user.displayName; // The display name of the user.

    return sendWelcomeEmail(email, displayName);
});


function sendWelcomeEmail(email, displayName) {
    const mailOptions = {
        from: '"Test" <noreply@test.com>',
        to: email
    };

    // The user subscribed to the newsletter.
    mailOptions.subject = `Welcome to hell!`;
    mailOptions.text = `Hey I hope you will enjoy our service.`;
    return mailTransport.sendMail(mailOptions).then(() => {
        console.log('New welcome email sent to:', email);
    });
}
  • 我确实启用了“允许安全性较低的应用”
  • 我确实在配置中看到了我的gmail地址和密码。我已在命令行中输入firebase functions:config:get
  • 验证了这一点

我收到以下错误 Invalid Login even when credentials are correct

1 个答案:

答案 0 :(得分:1)

我只是使用您在配置中添加的from:中的正确电子邮件地址解决了这个问题。

from: '"Test" <youremail@gmail.com>',