HELP: formatting email from script

Hi,
I created a script tha generate some output. Then I created a cron job to periodically execute my script and send an email with the standard output of my script.
The format of that output in a ssh console is like that:

****************************
*                          *
*  ...some text...         *
*  ...some text...         *
*  ...end of text...       *
*                          *
****************************

(I hope that you see in your browser that it’s a text inserted in a perfect rectangle of asterisks)
but when I receive the email, the content is like that:

****************************
* *
* ...some text... *
* ...some text... *
* ...end of text... *
* *
****************************

because the email content is html and the email client does what every html reader does: it eliminate the superfluous spaces.
But if before that text I insert some html tags (like <pre> for example), or I even insert a full html tags (<!DOCTYPE html>, <html>, <body> …), these tags are shown as a normal text before and after the output text of my script, and that text continues to be not formatted as I want it.

So, is there a way to obtain my goal with TrueNas emails?

Thanks for any tip.
Cheers.

@joeschmuck’s multi-report script sends decently-formatted emails; maybe checking it out will give you some ideas:

If can help: grab my sendmail (actually the same used by multi-report), i think that the custom email template functions in BETA will help you a lot to achieve this. They are still not released but, unless something unexpected comes up, they will be up at the end of this week.
If you don’t mind and wanna still try the beta to evaluate this route (and off course, i will appreciate any feedback):

  • build your custom html template, fullfill every dynamic field you need using this sintax: {myfield}
  • if you need to use curly brackets for style or anything else (except dyn fields), you need to escape them with a double curly braket, example .myclass {{ color:red}}
  • call the script with adding those 2 arguments: --use_template "myfile.html" --template_var '{"myfield": "myvalue" ...}' and everything will be replaced smoothly
  • there are a lot of responsive template on the net, you can also grab a couple of template that i use directly in the sendemail from the github repo, better than start from scratch :smile:

Instead this is an example of how can appear an email using the builtin UT_default_adv template:

colors used here are terrible :clown_face: but you can change them easily

--use_template "UT_default_adv" --template_var '{"bkcol": "#332D2D", "containerbkcol": "#FBFBFB", "containerwidth": "50%", "headerbkcol": "#3B71CA,#E4A11B", "containercol": "#DC4C64", "headercol": "#FFFFFF", "headercontent": "Template UT_default_adv"}'

the content (the lorem ipsum) will be your output.

1 Like

@lurgainn Use a Mono Spaced Font. It will solve your problem for spacing.

I solved in this way:

  • All the data I need are dimanically written in a html file
  • Then the script execute midctl --job mail.send and load the html file
  • Eventually the cron job execute the script but himself don’t send any email. The only email is sent within my script.

So in my html file I can use the tag <pre> and I obtain my goal.

Thanks anyway to everyone. Your tips helped me to do a better search on this forum and to find some other useful tips.

Cheers

Replace that with <pre style=\"font-size:16; font-family:Cascadia Code\"> and see the difference.