Meteor feature request - decouple account management functions from actual emails

I really wish there were a way to just generate (for example) an email verification link, rather than have to use sendVerificationEmail. The problem I’m running into is that I’ve got a complicated HTML email where I have to plug that URL into a very button. Because of how Meteor limits this functionality, I’m forced to use SendGrid’s <%body%> variable, which is getting malformed into a URI-encoded format, which is not working on mobile platforms.

I suppose for now, I can just look at the source code for sendVerificationEmail and pull out the part that generates the token and make my own function. But in the future, it would be nice to see that, along with password reset, etc, decoupled from Meteor’s email process.

1 Like

I agree with you. We also ended up creating our own tokens and urls for the enrolment and reset and here’s the code if it helps. We don’t verify email addresses so you’d have to add that Accounts.urls.verifyEmail . I assume the token creation is the same.

    "user.sendEmailTemplate": function(templateId, userId, reason) {

        // Code based from from Accounts.sendEnrollmentEmail() and Accounts.sendResetPasswordEmail()
        let user = Meteor.users.findOne({ _id: userId });
    
        let token = Random.secret();
        let when = new Date();
        let tokenRecord = {
            token: token,
            email: user.emailAddress(),
            when: when,
            reason: reason === AccountReasonEmailEnum.ResetPassword ? 'reset' : 'enroll'
        };

        Meteor.users.update(userId, { $set: {
            "services.password.reset": tokenRecord
        } });

        // before passing to template, update user object with new token
        Meteor._ensure(user, 'services', 'password').reset = tokenRecord;
    
        let url = reason === AccountReasonEmailEnum.ResetPassword ?
            Accounts.urls.resetPassword(token) : Accounts.urls.enrollAccount(token);

        ... 
        
    },

So then you encode that URL how you like and send the email however you want.

1 Like