javascript - Firebase:如何通过nodemailer发送的电子邮件模板发送重置链接?

标签 javascript node.js firebase

I implemented sending emails via nodemailer.

Now when I create new user, that new user get "welcome email".

Problem is cus that "welcome email" should contain option for resetting password.

How to add Firebase Resetting link in nodemailer email template?

  • 这是我的 nodemailer 电子邮件模板代码

    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: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="741a0d1d1f421a1a000100190547020e423411001c11061115185a1119151d18" rel="noreferrer noopener nofollow">[email protected]</a>',
       to: `${user.email}`,
       subject: 'Welcome to the Church Mutual Assignment Tool',
       text: 'Plaintext version of the message',
       html: output
     }
    
  • 这是我的 Nodemailer 代码:

      var mailer = require('nodemailer')
      var mailConfig = {
      host: 'smtp.ethereal.email',
      port: 587,
      auth: {
        user: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b8d6c1d1d38ed6d6cccdccd5c98bcec28ef8ddccd0ddcaddd9d496ddd5d9d1d4" rel="noreferrer noopener nofollow">[email protected]</a>',
        pass: '3cbRjkZdPquDqA725s'
      }
    }
    
    var transporter = mailer.createTransport(mailConfig)
    
    module.exports = transporter
    

最佳答案

Admin SDK 现在有一些方法可以让您做到这一点。查看 email action links 上的文档,特别是“生成密码重置电子邮件链接”部分。

// Admin SDK API to generate the password reset link.
const email = '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0f7a7c6a7d4f6a776e627f636a216c6062" rel="noreferrer noopener nofollow">[email protected]</a>';
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'
};

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

Ability to customize how the link is to be opened, through a mobile app or a browser, and how to pass additional state information, etc.

这听起来很有希望,允许它在浏览器中打开...但如果您正在开发网络 - 并且在未提供 iOS/Android 信息时功能会出错...那么恐怕您将不得不这样做这样做old fashioned approach并创建您自己的实现...但我倾向于这个 .generatePasswordResetLink 应该适合您。

关于javascript - Firebase:如何通过nodemailer发送的电子邮件模板发送重置链接?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54439036/

相关文章:

javascript - 基于函数参数的可选泛型

javascript - 启动浏览器进程失败! Ubuntu

Firebase - 在互联网离线时上传图像

node.js socket.io 这是内存泄漏吗?

json - 如何在 Windows 命令行上通过 html-minifier 将选项传递给 UglifyJS?

android - Firebase Android - startAt() 和 endAt() 无法正常工作?

javascript - 来自不同用户的消息在同一侧的问题

javascript - 从 JavaScript 中的函数参数中解构未知名称值

java - Easy ui 1.3.5 - 内部带有数据网格的对话框未加载

Javascript树遍历函数错误