Search code examples
emailmeteormandrillemail-verification

Signup with email verification in Meteor not working? How should it be done?


I'm trying to create my custom sign up page with email verification in Meteor. I want to use Mandrill for sending the verification email. In the server folder, I've a method-

addUser: function(user) {
    console.log("Adding User - ", user);
    var userOptions = {
        email: user.email, password: user.password,
        profile: {firstname: user.firstname, lastname: user.lastname}
    };

    var createdUser = Accounts.createUser(userOptions);
    console.log("CreatedUser-", createdUser);
    Accounts.onCreateUser(function(options, createdUser) {
        if (options.profile) {
            createdUser.profile = options.profile;
        }
        else {
            createdUser.profile = {};
        }
        Accounts.sendVerificationEmail(createdUser._id, createdUser.email);
        return createdUser;
    });

The Accounts.createUser method is inserting a record, but the emails are not going out. I've also defined the process.env.MAIL_URL with the Mandrill smtp credentials. I'm tired looking through the docs and checked a couple of blogs but nothing seems to work. If I remove createUser() then the user is not inserted in mongo db and onCreateUser() fails with exception. I've gone through the Meteor documents, but still confused about, how onCreateUser() works? How will the onCreateUser() method will get the options and user parameters? I've been stuck with this, any guidance/help is appreciated. After going through another question on stackoverflow, I removed the email pacakge. I do have wylio:mandrill added to the project. Do I need the email package?


Solution

  • I think you just need to set a config setting like so:

    Accounts.config({
      sendVerificationEmail: true
    });
    

    If this isn't set to true (and it's false by default), it will output the content of the email into the server console, which is good for testing, but bad for actually sending out emails obviously.

    I'd add the email package back in, I think you need that to send out emails. Hope that helps.