Question about sending email formatting for payload

Hello, new NodeRed player here.

Having fun extracting data from my Duet 3 card on my 3D Printer to email me useful informations.

So far, I have all I need, except the formatting of the data send in the email is horrible.

I get this:

{"status":"Printing from SD card","printPercent":80.9,"printTimeLeft":3751.6,"x":135.425,"y":121.557,"z":91.17,"currentBedTemp":50,"currentHotendTemp":210.3,"activeBedTemp":50,"activeHotendTemp":210,"stateBed":"Active","stateHotend":"Active","fileName":"0:/gcodes/cam holder.gcode"}

Is it possible to get this instead:

Status : Printing from SD card
printPercent : 80.9
printTimeLeft : 3751.6
x : 135.425

The format is in a single line of data right now and is kinda hard to read. I've messed with CSV but it is not really helping my cause as all I can get is all the data without the description, but still all on a single line.

I was thinking of inserting a break between each message in the payload. Is that possible?

Thanks in advance for the help!

Also, when I look at the debug, it shows up exactly like I want it for some reason with a JSON object converter.

See attached screenshot. This is the exact way i want it to show up..

That is not a JSON object, that is a Javascript object. A JSON object is a string, which I assume is what you started with. So it isn't a horrible email format at all, it is ideal as it is JSON. So now all you have to do is to build the text you want from the object. Start by reading the node red docs Working with Messages which will show you how to access the various attributes. Then I suggest maybe using a Template node (not ui-template) to format the text for putting in the email. The Information panel for the node shows you how to insert values from the payload into the string returned.
Feed the javascript object into the template, not the original JSON.

Thank YOU!! Template node was exactly what I was looking for!

Yes, I meant Javascript object, not JSON object.

Now I get this pretty sexy email:

Now to make it nicer... Use html in that template to get colour & formatting :slight_smile:

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.