代码之家  ›  专栏  ›  技术社区  ›  James Delaney

FireBase:如何通过从nodemail发送的电子邮件模板发送重置链接?

  •  1
  • James Delaney  · 技术社区  · 6 年前

    我实现了通过nodemail发送电子邮件。

    现在当我 创建新用户 ,新用户会收到“欢迎邮件”。

    问题是“欢迎电子邮件”应该包含的客户选项 正在重置密码。

    如何添加 FireBase重置链接 在nodemail电子邮件模板中?

    • 这是我的nodemail模板代码

      const output = `
       <p>You have access to the Church Mutual Assignment Tool.</p>
       <p>Follow this link to create new password for your account ${userRecord.email}:</p>
         <a href="${resetPasswordLink}">
           ${resetPasswordLink}
         </a>
         <p>Thanks,</p>
         <p>Your Church Mutual Assignment Tool team</p>
       `
       let message = {
         from: 'nyik6nntutmq3vz6@ethereal.email',
         to: `${user.email}`,
         subject: 'Welcome to the Church Mutual Assignment Tool',
         text: 'Plaintext version of the message',
         html: output
       }
      
    • 这是我的电子邮件号码:

        var mailer = require('nodemailer')
        var mailConfig = {
        host: 'smtp.ethereal.email',
        port: 587,
        auth: {
          user: 'nyik6nntutmq3vz6@ethereal.email',
          pass: '3cbRjkZdPquDqA725s'
        }
      }
      
      var transporter = mailer.createTransport(mailConfig)
      
      module.exports = transporter
      
    1 回复  |  直到 6 年前
        1
  •  1
  •   JeremyW    6 年前

    管理软件开发工具包现在有一些方法可以让你做这个精确的事情。查看上的文档 email action links 尤其是 生成密码重置电子邮件链接 “剖面图。

    // Admin SDK API to generate the password reset link.
    const email = 'user@example.com';
    admin.auth().generatePasswordResetLink(email, actionCodeSettings)
        .then((link) => {
            // Do stuff with link here
        })
        .catch((error) => {
            // Some error occurred.
        });
    

    完全公开-我实际上没有使用任何这些功能,我有点担心,有问题的页面涉及很多移动应用程序-所以你 可以 必须通过移动应用程序配置。

    const actionCodeSettings = {
        // URL you want to redirect back to. The domain (www.example.com) for
        // this URL must be whitelisted in the Firebase Console.
        url: 'https://www.example.com/checkout?cartId=1234',
        // This must be true for email link sign-in.
        handleCodeInApp: true,
        iOS: {
            bundleId: 'com.example.ios'
        },
        android: {
            packageName: 'com.example.android',
            installApp: true,
            minimumVersion: '12'
        },
        // FDL custom domain.
        dynamicLinkDomain: 'coolapp.page.link'
    };
    

    另一方面,该页面还表示,这些功能提供了以下功能:

    能够通过手机自定义链接的打开方式 应用程序或浏览器,以及如何传递附加状态信息等。

    这听起来很有希望,允许它在浏览器中打开…但是如果你是为网络开发的——如果没有提供iOS/android信息,功能就会出错……那么恐怕你得做 old fashioned approach 并创建自己的实现…但我倾向于这个 .generatePasswordResetLink 应该为你工作。