Loopback: Cannot change templating engine in User.verify() e-mails

Created on 26 Feb 2015  Â·  18Comments  Â·  Source: strongloop/loopback

The ejs templating engine is hardcoded into the loopback core (loopback.template function), and User.verify() uses it when sending confirmation e-mail to users, so I cannot use any other templating engine.

feature

Most helpful comment

:+1: trying to use jade. Maybe check extension of template, or just default to whatever set in app app.set('view engine', 'jade');

All 18 comments

Are you trying to use a different templating engine when using User.verify? Or for the entire app? Please create a test project on Github to reproduce the issue as per https://github.com/strongloop/loopback/wiki/Issues#bug-report and I will verify your issue.

I'm quite new to Loopback, so maybe I'm doing something wrong. I've tried to use different templating engines for the entire app (jade and handlebar so far), but they don't affect the e-mail sent from User.verify.

Correct me if I'm wrong, but it does look to me like this piece of code is hard-coded to always use ejs as a templating engine?:
https://github.com/strongloop/loopback/blob/master/lib/loopback.js#L176-L190

+1

Not sure why loopback is hardcoded to use ejs with loopback.template()

Same problem here, I try to use Mandrill, which stores its templates on the server, however I can't get around these default settings.

:+1: trying to use jade. Maybe check extension of template, or just default to whatever set in app app.set('view engine', 'jade');

facing the same problem. don't know, why loopback is not giving option to change verification email body?

Hi, this point is still valid. Is there a workaround for using handlebars?

Many thanks

Hi,
one of the possible reasons that the template is hard-coded is for ease of use for many users. You can change the text of the email body in models/user.js .. If there is a better suggestion for the loopback,template function, please submit a PR. Thanks.

For the possibility of using handlebars, jade, mandrill, I will get back to you on that.

+1

+1

+1

+1

@loay

For the possibility of using handlebars, jade, mandrill, I will get back to you on that.

I am in the process of using Mandril as an e-mail service. But in now way it seems possible to use Mandril since I cannot pass the mandrill template via the options to user.verify().

Do we have a solution for this, or will I be implementing a custom verification script?

@kwuite the user.verify() method calling the Email.send() to send the mail, the send method is implemented in the User model to use nodemailer. If you'd like to use another e-mail sender library, you can just simply write your own verify method by using your own mailer. The verify method is just to send out an email with the confirm endpoint token, and then you may write a context.res.redirect(301, "path") to your destination after sending out the verification email.

@zhenyanghua, thank you for your reply.

I resolved the issue by generating the token and then calling user.save so I can proceed with the call to mandrill.

context.req.app.models.Member.generateVerificationToken(member, function (err, token) {
    if (err) {
        return next(err);
    }

    member.verificationToken = token;
    member.save(function (err) {
        if (err) {
            next(err);
        }
        else {
            var verifyUrl = 'http://' + config.host + ':' + config.port + '/api/members/confirm?uid=' + member.memberId + '&redirect=/&token=' + token;

            Member.app.models.Email.send({
                    to: member.email,
                    from: '[email protected]',
                    subject: 'Thanks for registering.',
                    template: {
                        name: "verify-mail",
                        content: [
                            {
                                name: "firstname",
                                content: member.username
                            },
                            {
                                name: "verificationlink",
                                content: verifyUrl
                            }
                        ]
                    }
                },
                function(err, result) {
                    if(err) {
                        console.log(err);
                        return;
                    }
                    console.log(result);
                });
        }
        next();
    });
});

+1, the way verify() generates the email's html body is very hard to extend as it can only rely on loopback.template().

What would you think of a additional templateFn option ?

It would be especially useful when one has a template engine specific for email that can't rely on loopback.template(like https://github.com/crocodilejs/node-email-templates for CSS inlining)

If you use es6 in node, you can really just use ${} to write the
template, it is really flexible.

Zhenyang Hua

On Fri, Nov 11, 2016 at 9:24 AM, adrien-k [email protected] wrote:

+1, the way verify() generates the email's html body is very hard to
extend as it can only relies on loopback.template().

What would you think of a additional templateFn option ?

It would be especially useful when one has a template engine specific for
email that can't rely on loopback.template(like https://github.com/
crocodilejs/node-email-templates for CSS inlining)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/strongloop/loopback/issues/1138#issuecomment-259967491,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AF4VhmZvC6LlQ22NNBKXCZNyn40DmPbaks5q9HqNgaJpZM4DmKxh
.

This is possible now. Closing.

Was this page helpful?
0 / 5 - 0 ratings