如何使用Angular 2 Firebase通知所有者数据已插入Firebase

如何使用Angular 2 Firebase通知所有者数据已插入Firebase,angular,firebase,firebase-realtime-database,Angular,Firebase,Firebase Realtime Database,我有一个Firebase项目和新用户,并且数据被实时添加到数据库中。 我希望在数据库发生任何更改或添加新用户时得到通知 我们怎样才能做到这一点呢 我试着用谷歌搜索,但找不到,我只是想要一封firebase发给我的邮件,上面写着数据已更改或用户已添加 非常感谢这是Firebase云功能的一个很好的用例 您可以编写在将数据添加到数据库以及新用户首次通过身份验证时触发的函数。以下是一些可以了解更多信息的资源: Firebase示例的云函数特别有用,因为它们包括如何使用NodeEmailer发

我有一个Firebase项目和新用户,并且数据被实时添加到数据库中。 我希望在数据库发生任何更改或添加新用户时得到通知

我们怎样才能做到这一点呢

我试着用谷歌搜索,但找不到,我只是想要一封firebase发给我的邮件,上面写着数据已更改或用户已添加


非常感谢

这是Firebase云功能的一个很好的用例

您可以编写在将数据添加到数据库以及新用户首次通过身份验证时触发的函数。以下是一些可以了解更多信息的资源:

Firebase示例的云函数特别有用,因为它们包括如何使用NodeEmailer发送电子邮件。

将Jen的答案向前推一推。
Taking Jen's answer a bit more forward .

const functions = require('firebase-functions');
const nodemailer = require('nodemailer');
// Configure the email transport using the default SMTP transport and a GMail account.
// For Gmail, enable these:
// 1. https://www.google.com/settings/security/lesssecureapps
// 2. https://accounts.google.com/DisplayUnlockCaptcha
// For other types of transports such as Sendgrid see https://nodemailer.com/transports/
// TODO: Configure the `gmail.email` and `gmail.password` Google Cloud environment variables.
const gmailEmail = encodeURIComponent(functions.config().gmail.email);
const gmailPassword = encodeURIComponent(functions.config().gmail.password);
const mailTransport = nodemailer.createTransport(
    `smtps://${gmailEmail}:${gmailPassword}@smtp.gmail.com`);

// Your company name to include in the emails
// TODO: Change this to your app or company name to customize the email sent.
const APP_NAME = 'Cloud Storage for Firebase quickstart';

// [START sendWelcomeEmail]
/**
 * Sends a welcome email to new user.
 */
// [START onCreateTrigger]
exports.sendWelcomeEmail = functions.auth.user().onCreate(event => {
// [END onCreateTrigger]
  // [START eventAttributes]
  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.
  // [END eventAttributes]

  return sendWelcomeEmail(email, displayName);
});
// [END sendWelcomeEmail]


// Sends a welcome email to the given user.
function sendWelcomeEmail(email, displayName) {
  const mailOptions = {
    from: `${APP_NAME} <noreply@firebase.com>`,
    to: email
  };

  // The user subscribed to the newsletter.
  mailOptions.subject = `Welcome to ${APP_NAME}!`;
  mailOptions.text = `Hey ${displayName || ''}! Welcome to ${APP_NAME}. I hope you will enjoy our service.`;
  return mailTransport.sendMail(mailOptions).then(() => {
    console.log('New welcome email sent to:', email);
  });
}
const functions=require('firebase-functions'); const nodemailer=require('nodemailer'); //使用默认SMTP传输和GMail帐户配置电子邮件传输。 //对于Gmail,启用以下功能: // 1. https://www.google.com/settings/security/lesssecureapps // 2. https://accounts.google.com/DisplayUnlockCaptcha //有关其他类型的传输,如Sendgrid,请参阅https://nodemailer.com/transports/ //TODO:配置`gmail.email`和`gmail.password`谷歌云环境变量。 const gmailEmail=encodeURIComponent(functions.config().gmail.email); const gmailPassword=encodeURIComponent(functions.config().gmail.password); const mailTransport=nodemailer.createTransport( `smtps://${gmailmail}:${gmailPassword}@smtp.gmail.com`); //电子邮件中要包含的公司名称 //TODO:将其更改为您的应用程序或公司名称,以自定义发送的电子邮件。 const APP_NAME=‘Firebase快速启动的云存储’; //[开始发送电子邮件] /** *向新用户发送欢迎电子邮件。 */ //[在创建触发器时启动] exports.sendWelcomeEmail=functions.auth.user().onCreate(事件=>{ //[结束onCreate触发器] //[启动事件属性] const user=event.data;//Firebase用户。 const email=user.email;//用户的电子邮件。 const displayName=user.displayName;//用户的显示名称。 //[结束事件属性] 返回sendWelcomeEmail(电子邮件,显示名称); }); //[结束发送电子邮件] //向给定用户发送欢迎电子邮件。 函数sendWelcomeEmail(电子邮件,显示名称){ 常量邮件选项={ 发件人:`${APP_NAME}`, 收件人:电子邮件 }; //用户订阅了时事通讯。 mailpoptions.subject=`欢迎使用${APP_NAME}!`; mailOptions.text=`Hey${displayName | |''''}!欢迎使用${APP|u NAME}。希望您能享受我们的服务。`; 返回mailTransport.sendMail(mailpoptions)。然后(()=>{ console.log('新的欢迎电子邮件发送到:',电子邮件); }); }
有关更多信息,请查看此