Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

verify email using accounts.ui package

I want to send a verification email when some user is created. I use the accounts-password package, so any Accounts methods are called in my code.

I read in documentation that I need to call:

Accounts.sendVerificationEmail(userId, [email])

but the problem is that I don't know when to call it.

I tried to call in the callback function of Accounts.onCreateUser(func) but the user had not been created yet in the database.

Any ideas?

like image 451
nsblenin Avatar asked Jan 31 '13 00:01

nsblenin


3 Answers

on the serverside:

Accounts.config({sendVerificationEmail: true, forbidClientAccountCreation: false}); 

got the answer from the comments above.

like image 125
Laurens Avatar answered Nov 22 '22 06:11

Laurens


sendVerificationEmail is only available server-side. What I usually do is to use a setInterval inside onCreateUser to wait for Meteor to create the user before sending an email.

Read More: Verify an Email with Meteor Accounts.

// (server-side)
Accounts.onCreateUser(function(options, user) {  
  user.profile = {};

  // we wait for Meteor to create the user before sending an email
  Meteor.setTimeout(function() {
    Accounts.sendVerificationEmail(user._id);
  }, 2 * 1000);

  return user;
});
like image 26
Julien Le Coupanec Avatar answered Nov 22 '22 05:11

Julien Le Coupanec


You need specify mail in enviroment variables. Then use Accounts.sendVerificationEmail(userId, [email]) in callback of Account.onCreateUser sorry for mistake and delay.

Like this (below is full example js file):

Template.register.events({
'submit #register-form' : function(e, t) {
  e.preventDefault();
  var email = t.find('#account-email').value
    , password = t.find('#account-password').value;

    // Trim and validate the input

  Accounts.onCreateUser({email: email, password : password}, function(err){
      if (err) {
        // Inform the user that account creation failed
      } else {
        // Success. Account has been created and the user
        // has logged in successfully.
       Accounts.sendVerificationEmail(this.userId, email);
      }
    });

  return false;
}  });

if(Meteor.isServer){
   Meteor.startup(function(){
      process.env.MAIL_URL='smtp://your_mail:your_password@host:port'
   }
}

I refered to this pages : http://blog.benmcmahen.com/post/41741539120/building-a-customized-accounts-ui-for-meteor

http://sendgrid.com/blog/send-email-meteor-sendgrid/

How come my Meteor app with accounts package is not sending a verification email?

like image 30
despi23 Avatar answered Nov 22 '22 05:11

despi23