Skip to content

Cannot change templating engine in User.verify() e-mails #1138

Closed

Description

@mirow

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.

Activity

  1. superkhau commented on Feb 26, 2015

    @superkhau
    Contributor

    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.

  2. mirow commented on Feb 27, 2015

    @mirow
    Author

    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

  3. stringbeans commented on May 8, 2015

    @stringbeans

    +1

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

  4. arne-s commented on Jun 28, 2015

    @arne-s

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

  5. raabbajam commented on Jul 7, 2015

    @raabbajam

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

  6. shbhsngh commented on Nov 24, 2015

    @shbhsngh

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

  7. Fabrik19SH commented on Mar 20, 2016

    @Fabrik19SH

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

    Many thanks

  8. loay commented on Apr 7, 2016

    @loay
    Contributor

    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.

  9. elbarto132 commented on Apr 21, 2016

    @elbarto132

    +1

  10. pmoelgaard commented on Apr 22, 2016

    @pmoelgaard

    +1

  11. rpalacio86 commented on Jun 13, 2016

    @rpalacio86

    +1

  12. adanmuguirofoo commented on Jun 28, 2016

    @adanmuguirofoo

    +1

  13. kwuite commented on Sep 30, 2016

    @kwuite

    @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?

  14. zhenyanghua commented on Sep 30, 2016

    @zhenyanghua

    @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.

  15. kwuite commented on Sep 30, 2016

    @kwuite

    @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: 'admin@example.com',
                        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();
        });
    });
  16. adrien-k commented on Nov 11, 2016

    @adrien-k
    Contributor

    +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)

  17. zhenyanghua commented on Nov 11, 2016

    @zhenyanghua

    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 notifications@github.com 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
    #1138 (comment),
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AF4VhmZvC6LlQ22NNBKXCZNyn40DmPbaks5q9HqNgaJpZM4DmKxh
    .

  18. ritch commented on Nov 29, 2016

    @ritch
    Member

    This is possible now. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions