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



如何将验证链接从默认的 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,
});
} 

以防万一将来有人在寻找这个,我在流星论坛上找到了答案: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,
});
},

最新更新