Hey @marcuslma, the documentation shared by @paulishca could be helpful because the Accounts.onCreateUser() function is called whenever a new user is created.
To test this function, create a new file called accounts.js and import it into your main.js file:
import { Accounts } from 'meteor/accounts-base';
Accounts.onCreateUser((options, user) => {
console.log('onCreateUser');
console.log(options, user);
// Add your logic to send the email here
});
I added some console.log() statements so you can test it and see how it works. Now, when you insert a new user, the onCreateUser() function above will be called, and you can add your email sending logic inside it.
Hi @fredmaiaarantes
I’m using Accounts.onCreateUser to put extra data on my users.
But I’m not sure about something, this is called before or after user insertion?
Because what I need to do is send a welcome email on user insertion.
Accounts.validateNewUser runs after Accounts.onCreateUser but to make sure the account has been created, you can trigger email sending on Accounts.onLogin event, you will need a flag to mark which account you sent welcome email already.