【问题标题】:Using email trigger extension firebase in JavaScript在 JavaScript 中使用电子邮件触发器扩展程序 firebase
【发布时间】:2021-04-13 02:07:33
【问题描述】:

我为 Firebase 添加了电子邮件触发器的扩展。我有这个功能:

firestore
  .collection("profiledata")
  .doc(user.uid)
  .update({
    accountStatus: "active",
  })
  .then(() => {
    //here, I want to put the Firebase code
    props.history.push("/clients");
  });

但是,当我将 Firebase 代码放入其中时:

firestore
  .collection("gianluca@piersolutions.ca")
  .add({
    to: "contact@piersolutions.ca",
    message: {
      subject: "Hello from Firebase!",
      text: "This is the plaintext section of the email body.",
    },
  })
  .then(() => console.log("Queued email for delivery!"));

props.history.push("/clients");

在我的 IDE 中看起来像这样:

我不知道为什么它不允许我把这段代码放在这里!我该如何解决?

【问题讨论】:

  • 你能分享你的扩展配置吗?您应该写入哪个集合以触发电子邮件发送?
  • @RenaudTarnec 我实际上已经编辑了我的问题。它插入到firestore集合中。但它给出了错误Error: Failed to deliver email. Expected at least 1 recipient. 但我有一个收件人?我正在使用触发电子邮件 firebase 扩展。 firebase.google.com/products/extensions/firestore-send-email
  • 看我的回答。配置扩展时需要使用自己声明的集合吗?

标签: javascript firebase google-cloud-firestore


【解决方案1】:

如以下article 中所述,要通过扩展程序发送电子邮件,您需要在“电子邮件文档集合”字段中配置的集合中创建一个文档。

那么,如果这个集合命名为mail,如上例所示,则需要进行如下操作:

firestore.collection("profiledata").doc(user.uid)
    .update({
        accountStatus: "active"
    })
    .then(() => {
        return firestore.collection('mail').add({
            to: ['someone@example.com'],
            message: {
                subject: 'Hello from Firebase!',
                text: 'This is the plaintext section of the email body.',
                html: 'This is the <code>HTML</code> section of the email body.',
            }
        });
    })
    .then(() => {
     
        props.history.push('/clients')

    });

【讨论】:

  • 是的,我这样做了,我得到了这个错误:Error: Invalid login: 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information. [CH2PR07CA0052.namprd07.prod.outlook.com]
  • 您在连接到电子邮件提供商时遇到问题。我无法为您提供更多帮助,因为它特定于电子邮件提供商。您应该通过以下方式找到更多信息:google.com/…
猜你喜欢
  • 2022-11-20
  • 2022-11-20
  • 2021-05-23
  • 2020-11-08
  • 2021-06-21
  • 1970-01-01
  • 1970-01-01
  • 2020-11-06
  • 1970-01-01
相关资源
最近更新 更多