简体   繁体   English

流星帐户电子邮件验证

[英]Meteor accounts Email Verification

How do I send an email verification to a user with a custom message and a custom from parameter instead of the default one. 如何使用自定义消息和自定义from参数(而不是默认参数)向用户发送电子邮件验证。

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

When I use that method I get the default meteor verification email sent. 当我使用该方法时,会收到默认的流星验证电子邮件。 How do I change the parameters and where should I change them from? 如何更改参数以及应从何处更改参数?

You can create your own function to send custom HTML using templates, you can event pass simple HTML to instead of template file. 您可以创建自己的函数以使用模板发送自定义HTML,也可以将简单HTML事件传递给模板文件而不是模板。 Here is code: 这是代码:

'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");
        }
  },

You can do it like: 您可以这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM