Meteor帐户电子邮件验证

时间:2016-08-03 14:47:37

标签: javascript meteor reactjs

如何使用自定义消息和自定义参数(而非默认参数)向用户发送电子邮件验证。

Meteor.methods({
    sendveryficationmail: function (theuserId, themail) {
        this.unblock();
        Accounts.sendVerificationEmail(theuserId);
    }
});

当我使用该方法时,我会收到默认的流星验证电子邮件。如何更改参数以及从哪里更改参数?

2 个答案:

答案 0 :(得分:1)

您可以创建自己的函数以使用模板发送自定义HTML,您可以将事件传递给简单的HTML而不是模板文件。这是代码:

'sendVerificationEmail':function (emailId) {
        Meteor.users.update({'emails.address': emailId}, {$unset: {'services.email.verificationTokens': 1}});
        var user = Meteor.users.findOne({"emails.address": emailId});
        if (user) {
                if( user.emails.find(email=> email.address === emailId ).verified ){
                    throw new Meteor.Error("Email already verified");
                } else {
                    var userInfo = user.profile;
                    var emailId = user.email[0].address;
                    Accounts.emailTemplates.siteName = "NJAL";
                    Accounts.emailTemplates.from = "myTest <community@myTest.com>";
                    Accounts.emailTemplates.verifyEmail.subject = function(user) {
                        return "Account Verification Required";
                    };
                    Accounts.emailTemplates.verifyEmail.html = function (user, url) {
                         SSR.compileTemplate( 'registartionEmail', Assets.getText( 'email_templates/registration_confirm.html' ) );
                        var res=url.split("/");
                      var emailData = {
                            "designer_name": userInfo.fname + " "+ userInfo.lname,
                            "url": "http://domain.com/pages/verify/?token="+res[res.length-2]+"/"+res[res.length-1],
                            "emailId": emailId,
                        };
                        return SSR.render( 'registartionEmail', emailData );
                    };
                    Accounts.sendVerificationEmail(user._id, emailId);
                }
        } else {        
            throw new Meteor.Error("Email does not exist");
        }
  },

答案 1 :(得分:0)

你可以这样做:

Meteor.startup(function() {
    Accounts.verifyEmail = {
       from: 'custom from',
       subject: 'your subject',
       text: 'Your text',
       html: 'Your html'
    }
}
相关问题