Exception in delivering result of invoking 'createUser': TypeError: _accountsBase.Accounts.sendVerificationEmail is not a function

So I’ve been stuck for three hours now on this seemingly simple thing, sending a verification email to a user on registration.

Actual error is:

Exception in delivering result of invoking ‘createUser’: TypeError: _accountsBase.Accounts.sendVerificationEmail is not a function

/imports/api/users/methods.js

import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

export const userSendVerificationEmail = function() {
  let userId = Meteor.userId();
  if ( userId ) {
    return Accounts.sendVerificationEmail( userId );
  }
};

I’m not sure what I need to change since I’m following the example here: https://github.com/meteor/todos/blob/82b493da1893d8e5d6bca60f212cdab841f31903/imports/startup/server/reset-password-email.js

did u try wrapping it in a isServer call, i believe sendVerificationEmail is a server only function

Now it looks like this, no error but no email sending or console output in my terminal either.

import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';

export const userSendVerificationEmail = function() {
  let userId = Meteor.userId();
  if (userId && Meteor.isServer) {
    console.log("Sending");
    return Accounts.sendVerificationEmail( userId );
  }
};

Any other suggestions?

if you get no console output its not executing :o

try doing deleting the userId condition and check if you at least get the console.log statement in your terminal

I removed the userId condition and it’s still not working.

Maybe a Foobar example of a simple component calling a method would be enough for me to grok this lol.

Under what file path should this method be? It’s currently in: /imports/api/users/methods.js

path of the method is fine as long as you also import it to the server.

By putting it there you are declaring it on the client…so you have to also import it to the server (example app uses register-api.js) to do so.

Show the code where you are calling the method

This entire thing I’m working is open source, maybe you can take a peek and see where I dun goofed?

Error is:

Uncaught Error: 
Cannot find module '../../api/users/server/methods.js'

https://github.com/nanote-io/nanote-web/blob/master/imports/ui/pages/RegisterPage.jsx#L4

Is it because I can’t import a file that’s in a folder called Server? I’m super confused. :frowning:

methods.js should not be in a server folder…else it is not defined on the client.

Pull it out of the server folder then if your root/server/main.js import the methods.js file

If I import the method file in root/server/main.js how do I call it from RegisterPage.jsx? I need to invoke the Meteor method from the component.

Import method name if the file you want to use it in

import { userSendVerificationEmail } from '../../api/users/methods.js';

then call it

userSendVerificationEmail.call

I just pushed some changes to the repo based on your advice, no more crashes, but it still isn’t sending the email or showing me the console output for the Meteor.isServer conditional. :frowning:

https://github.com/nanote-io/nanote-web/commit/a52b6f1582c710f46f7052119d7052e62f7c2b1b

Thanks so much for the help here, I feel like I’m super close lol.

did you try taking userId out of the isServer condition after you made your other changes?

I need that userId to send the verification email.

ya but you can just get it when u are on the server , i.e. after the condition…so jsut try removing it to see if the method gets executed on the server…thats the main issue right now

1 Like

Removed the conditional, still no terminal output for console.log. :frowning:

the problem is that u are using a normal function not a method…so it will not work on the server…

either use the ‘old’ way of

Meteor.methods({
 'userSendVerificationEmail': function(){
 //do method stuff here
}
})

or look at wrapping it your function with the validated method package (recommended in the guide)

1 Like

Stupid question, but did you set MAIL_URL?

1 Like

It’s working! Making notes here on where I screwed up, looks like I’m just going to use ValidatedMethod. :smiley:

2 Likes