困惑如何自定义流星验证电子邮件

时间:2018-09-20 21:44:40

标签: meteor

如何将验证链接从默认的Meteor方法转换为使用sendgrid stmp的自定义电子邮件方法。

这是一种流星验证方法,可以单独使用并具有我想要的链接:

sendVerificationLink() {
 let userId = Meteor.userId();
   if ( userId ) {
     return Accounts.sendVerificationEmail( userId );
    }
  },

这是我使用sendgrid的自定义方法,除我无法弄清楚如何获得带有自定义标记的链接外,其他所有方法都有效:

'signupEmail' (submission) {
   this.unblock();
   const link = ''
   const message = `welcome ${submission.firstname} `
   const text = `welcome ${submission.firstname}. Please verify your 
   account ${link}`
   Email.send({
     from: "hi@test.com",
     to: submission.email,
     subject: message,
     text: text,
      html: text,
    });
} 

1 个答案:

答案 0 :(得分:0)

以防万一将来有人在寻找这个问题,我在流星论坛上找到了答案:https://forums.meteor.com/t/how-to-get-verification-link-for-custom-sent-verification-email/22932/2

基本上,我添加了令牌记录并将其保存在数据库中。然后将令牌与方法:Accounts.urls.verifyEmail一起使用,该方法创建了要在电子邮件中插入的链接。

这是我最后的方法:

'signupEmail' (submission) {
    this.unblock();
    let userId = Meteor.userId();
    var tokenRecord = {
      token: Random.secret(),
      address: submission.email,
      when: new Date()};

      Meteor.users.update(
        {_id: userId},
        {$push: {'services.email.verificationTokens': tokenRecord}}
      );
      const verifyEmailUrl = Accounts.urls.verifyEmail(tokenRecord.token);

      const message = `welcome ${submission.firstname} `
      const text = `welcome ${submission.firstname}. Please verify your account ${verifyEmailUrl}`
      Email.send({
        from: "hi@test.com",
        to: submission.email,
        subject: message,
        text: text,
        html: text,
      });
  },