Sunday, 16 April 2017

how to render dynamic variables from the mongodb and replace them before sending email?

I can't store the whole html in the mongodb coz of encoding json errors.

Here's my sample email that works but i want to be able to save content in the mongodb.

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
  <title></title>
</head>

<body>
<p></p>
  <p>Dear ,</p>
  <br />
<p>This is Peter from  </p>

<p>I would like to know the status of the property</p>
<p>   in </p>
<br> 
<p> Please give me a call asap:   @943-454-3443</p>

so the email with variable names work great but now i want to save the in the mongo.

Here's where the node backend using node_mailer converts the above html content and then later send the email.

   res.render(path.resolve('modules/users/server/templates/statusOfProperty'), {
          emailContent: properties[0].emailTemplate,
          name: properties[0].agent_name,
          appName: properties[0].agent_name,
          address: properties[0].address,
          city: properties[0].city,
          url: 'baseUrl'
      }, function(err, emailHTML) {
             if (err) {
                 // console.log(err);
                 return res.status(400).send({
                     message: errorHandler.getErrorMessage(err)
                 });
             } else {

A mosts of the variables are replaceable & I can chnage the content of inner html by putting the variable inside the tag, but the issue is when i want to render variables inside the variable which is coming from mongodb ?

In the below sample mongo object, I'm unable to dynamically replace the variable with the content provided by the res.render function { "last_date_call": "-", "call_priority": "-", "financial": "Sale", "emailTemplate":"This is coming from mongodb sir Dear name => is also coming from mongodb" }

Here's the email output.

enter image description here

fyi: It would be nice to know if there's an already a wysiwig editor for all this job plus able to save it in mongodb.



via JP.

No comments:

Post a Comment