QingYun
QingYun

Reputation: 869

How to use sendEnrollmentEmail in Meteor

The doc about sendEnrollmentEmail is too short, I can not understand how it works.

My code can not create a new user. It only prints the email content in the console and the link in the email http://localhost:3000/#/enroll-account/D4SGgWerKrdNfYrJW only redirects to localhost:3000/ and I can not find the token that should be pass to Accounts.resetPassword as the doc said.

Meteor.methods({
  createNewUser: function (username, email) {
    Meteor.call("validateUsername", username);
    Meteor.call("validateEmail", email);
    var userId = Accounts.createUser({username: username, email: email});
    Accounts.sendEnrollmentEmail(userId);
  }
});

Is there any example about sendEnrollmentEmail? thanks :)

Upvotes: 3

Views: 3592

Answers (1)

Jan Rudovsky
Jan Rudovsky

Reputation: 186

You did everything correct.. I tried to get it working and it works for me fine. (Which version of meteor are you using?)

if (Meteor.isServer) {    
  Meteor.methods({
  createNewUser: function (username, email) {
    // i recommend to create user with initial password otherwise it will be empty string
    var userId = Accounts.createUser({username: username, email: email, password: 'initialPassword'});
    Accounts.sendEnrollmentEmail(userId);
  }
  });
}

After that I got "email" in console, click on the link open my browser where popup "window" for password change

Upvotes: 8

Related Questions