Meteor:如何获取帐户密码重置令牌,没有电子邮件

时间:2015-12-07 21:11:04

标签: meteor meteor-accounts

我希望使用sendgrid模板发送帐户密码重置电子邮件。

所以基本上不使用函数Accounts.sendResetPasswordEmail而是需要函数Accounts.getResetPasswordURL

这将给我一个密码重置URL,我可以用它发送到将在模板中使用的sendgrid。

那我该怎么做呢?我如何使用Meteor来获取密码重置URL但实际上不发送电子邮件?我将使用对sendgrid的API调用手动发送带有URL的电子邮件。

2 个答案:

答案 0 :(得分:1)

注意:我没有使用过sendgrid,所以我要去API over here

首先,您要将Meteor配置为使用Sendgrid's SMTP servers。这样,您就可以直接通过Meteor发送电子邮件:

Meteor.startup(function(){
    process.env.MAIL_URL = "smtp://" + sendgridUsername + ":" + sendgridPasswordOrAPIkey + "@smtp.sendgrid.net:465";
});

您可以更改重置电子邮件的默认模板。这可以通过修改Accounts.emailTemplates

来完成
Accounts.emailTemplates.resetPassword.html = function(user, url){
    // url contains the reset url! :)
    var result;
    var sendgridTemplateId = ''; // Set this to the template id you're using in sendgrid
    try {
        // Get sendgrid template
        // API link: https://sendgrid.com/docs/API_Reference/Web_API_v3/Template_Engine/templates.html
        result = HTTP.get("https://api.sendgrid.com/v3/templates/" + sendgridTemplateId);
        result = result.data.templates[0].versions[0].html_content;
        // then insert URL to the template
    } catch (error) {
        console.error('Error while fetching sendgrid template!', error);
        return false;
    }
    return result;
};

现在当你使用Accounts.sendResetPasswordEmail()时,将使用上面的模板,它实际上只是获取sendgrid模板并返回它!

答案 1 :(得分:0)

目前执行该程序的方式实际上是不可能的。

accounts-password包生成随机令牌,并以sendResetPasswordEmail()方式发送电子邮件。

您可以分叉包,按照完成in the original method的方式生成自己的令牌,或者更改email包的行为以自行处理电子邮件。

相关问题