Michael
Michael

Reputation: 127

How to pass a variable in an email with Meteor

Ok i updated my code and now it looks like this

import { meteorhacksssr } from 'meteor/meteorhacks:ssr';

SSR.compileTemplate('InviteEmail', Assets.getText('InviteEmail.html'));
var emailData = {
  name: "tom"
};


Meteor.methods({
    addInvite(code) {
          Invites.insert({
            code : code,
            sentTo: '[email protected]',
            accepted: false
        });

         var emailData = {
             code: code
};

    Email.send({
        to: "[email protected]",
        from: "[email protected]",
        subject: "Example Email",
        text: SSR.render('InviteEmail', emailData),
});
    }
});

Here is my Html template in the server folder with the name InviteEmail.html

<template name="InviteEmail">
  <html>
      <body>
          hi {{code}}
      </body>
</html>
</template>

But now my app is crashing cmd says : Error: Unknown asset: InviteEmail.html I installed the package and imported it now i have to fix it

Thanks for every help ;)

Upvotes: 1

Views: 205

Answers (1)

Amit kumar
Amit kumar

Reputation: 6147

To handle the process of converting templates into raw HTML on the server, we need to add a package to our application called meteorhacks:ssr install it using meteor add meteorhacks:ssr

for passing any data to replace use handlebars helpers like {{name}} let email.html is

<html><body>hii {{name}}</body></html>

and our email code should be like this

SSR.compileTemplate('htmlEmail', Assets.getText('email.html'));

var emailData = {
  name: "tom"
};

Email.send({
  to: "[email protected]",
  from: "[email protected]",
  subject: "Example Email",
  html: SSR.render('htmlEmail', emailData),
});

for more info read this https://themeteorchef.com/tutorials/using-the-email-package

and you can also use replace function of javascript for this

Upvotes: 1

Related Questions