在firebase函数中设置mailgun

在firebase函数中设置mailgun,firebase,google-cloud-functions,mailgun,Firebase,Google Cloud Functions,Mailgun,通过以下教程,我非常努力地在firebase函数上使用mailgun: 我希望在我的实时数据库中有东西被推送到特定节点时收到电子邮件通知。到目前为止,代码如下所示: const functions = require('firebase-functions') const mailgun = require('mailgun-js')({ apiKey: 'key-<######>', domain: '<mydomain>.com', }) exports.

通过以下教程,我非常努力地在firebase函数上使用mailgun:

我希望在我的实时数据库中有东西被推送到特定节点时收到电子邮件通知。到目前为止,代码如下所示:

const functions = require('firebase-functions')
const mailgun = require('mailgun-js')({
  apiKey: 'key-<######>',
  domain: '<mydomain>.com',
})

exports.sendEmail = functions.database
  .ref('someParent/someChild')
  .onWrite(event => {
    // only trigger for new users [event.data.previous.exists()]
    // do not trigger on delete [!event.data.exists()]
    if (!event.data.exists() || event.data.previous.exists()) {
      return
    }

    const post = event.data.val()
    console.log(post)
    const { email, message } = post

    const data = {
      from: 'mailgun@firebase.com <is this free choice???>',
      subject: 'Hello Word!',
      html: `<p>It's alive!!!</p>`,
      'h:Reply-To': mail,
      to: '<myOwn>@gmail.com',
    }

    mailgun.messages().send(data, function(error, body) {
      console.log(body)
    })
  })

我也有同样的问题。你明白了吗>我发现if语句导致了问题-修复得很好,但找到了比电子邮件更好的解决方案-做了一些IoT来代替:-)你能分享你所做的吗?我将为一个简单的web表单编写一些代码。我只需要在写入数据时得到通知。有关更多信息,请参阅我也遇到了同样的问题。你明白了吗>我发现if语句导致了问题-修复得很好,但找到了比电子邮件更好的解决方案-做了一些IoT来代替:-)你能分享你所做的吗?我将为一个简单的web表单编写一些代码。我只需要在写入数据时得到通知。有关更多信息,请参阅
const functions = require('firebase-functions')
const mailgun = require('mailgun-js')({
  apiKey: 'key-<######>',
  domain: '<mydomain>.com',
})

exports.sendEmail = functions.database
  .ref('someParent/someChild')
  .onWrite(event => {
    // Do some checking of data if needed. 

    const post = event.data.val()
    console.log(post)
    const { email, message } = post

    const data = {
      from: 'mailgun@firebase.com <is this free choice???>',
      subject: 'Hello Word!',
      html: `<p>It's alive!!!</p>`,
      'h:Reply-To': mail,
      to: '<myOwn>@gmail.com',
    }

    return mailgun.messages().send(data, (error, body) => {
      console.log(body)
    })
  })