The problem here (as I understand it) seems to be that midclt is choking on this line: midclt call -job mail.send '{"subject": "'"${subject}"'", "html": "'"${html_data}"'", "to": ["'"${email}"'"]}'
The ${html_data} variable contains the contents of logfile_tmp.txt which is a text file with mixed in html.
As a comparison, even a file containing only the following results in the dict expected-error:
Hello
World
So the question is if one can have those line breaks without them being interpreted by the shell, or possibly midclt.
but as you see i have encoding everything (the sintax for using jq is provided by chat gpt but having ask specifically for this should be fine anyway xD)
@oxyde
That code worked ! Well for sending a single HTML file without attachments.
Iām still trying to understand why it works. I understand the \" is a literal quotation, but why does it need to be on multiple lines? Hey, it works and Iām not fussing.
I had to make some changes to Multi-Report so it would use sendmail on earlier versions of TrueNAS and this new stuff for 24.10.1 and later. Now Iām trying to figure out why curl is giving me a headache. I will work on it some more tomorrow but Iām close. I can attach multiple files, it is just the html code that is not longer liked. Simple html is fine.
And stuck yet again. @oxyde Time to roll out that ChatGPT solution again
The last issue is sending the HTML file in the body, and having attachments at the same time. It appears curl really doesnāt like semicolons, it fails on the first one it finds. I have found a bit of data on this issue however no solutions, well that were obvious to me. I have to say it again, Iām no programmer.
Here is what I have right now:
This variable works fine if I remove the semicolon after the word āfileā and I can send the html and attachments without issue. But add that semicolon and it fails.
html_data="Check the attached <b>Chart.html</b> file; to view the chart that should be in the body of this email."
And you will of course need the attachment.json file pointing to at least one file to attach.
In my searching I never saw some āspecialā formatting as @oxyde had for the mail.send call.
And I am virtually done with the script overall. I can send out an email with attachments provided the HTML has no semicolons. With this fact, I can attach the actual HTML file as an attachment and a person would need to open the āchart.htmlā file to see the typical chart I want in the email body.
Iām on hold for now, been working different angles all morning with just failure after failure, and frustration. I now need to 3-D design and print a garage remote control holder for my wifes new car. There is no good location to place it in the car right now. The design part will be tricky but it will keep me busy for hours as I learn more about Fusion 360.
The json encode is quite useless there (no reason to ask to chat gpt now ), i will continue make some test to find the right pattern (or is something documented somewhere?)
As you can see from my snippet⦠for me the right endpoint is http://127.0.0.1:880/_upload/ and not http://127.0.0.1/_upload/, because TN itself is exposed to another port
Afaik, assuming that using API mean to use a GET curl⦠Donāt you will have the exact same problem? But i think in the same way that there must be another trick to achieve this without let user bound the used port into the script
Unless one can conjure up the used webGUI port using midclt, then yes, I guess thatās going to be something you need to ask for during initial setup. Default to the standard port but ask if it should be changed.
If that is how it goes itās not going to be a hands-off upgrade for some of the current users. They will need to supplement their current configuration if they use a non-standard port.
This gathers the whole configuration on a single line, pipes it to jq to make it more readable and then just spits out the line with the current http-port for the webGUI: midclt call system.general.config | jq | grep ui_port | sed "s/[^0-9.]*//g"
Is that something you can build on?
I fully expect someone can make that grep/sed concoction prettier. Feel free.
OMG, That was so long ago but yes I remember it well. I will still fight for the HTML version if I can get there.
@oxyde Thanks for all the effort you have put into this. I of course ran into another problem. I feel it will be this way all the time. Maybe time for a different path.
With the change you presented, that small test file passes without issue. Now give this one a try, rename it to .html to view via web browser to see what it should look like. This is the same file which I can add as an attachment without issue, but who wants to open an attachment when it should be seen in the message body. I have done no processing on the attached file. html_data_full_raw.txt (42.8 KB)
To send a message without an attachment (using mail.send) I need to preprocess it with html_data=$(cat /tmp/logfile_tmp | jq -Rs .) and then it will send. The full set of commands are:
As for sending the attached file With Attachments, here is the curl command line, which of course fails with an error (the error changes depending on the preprocessing I do, or donāt do).
But what is the preprocessing that is needed to make it work? Iām starting to dislike this project. Maybe tossing it into a Docker or Jail is what I need to do so I can control more on how things work/change. I will explore that in time. I do not desire to take a step backwards and would rather just present an attachment and a basic body message of āyour system has not error messagesā or āYou got BIG troubles buddy!ā or āHow are you at replacing a drive?ā
That is where Iām at for the moment as much as I would dislike it.
Absolutely! Thanks for saving me the time.
I can see it becoming something like this: local_address=$(midclt call system.general.config | jq | grep ui_port | sed "s/[^0-9.]*//g")
The the curl line changing to curl -k ālocation-trusted -v -i -u truenas_admin:puppy123 --form-string 'data={"method": "mail.send", "params": [{"subject": "'"${subject}"'", "to": ["'"${Email}"'"], "html": "'"${html_data}"'", "attachments": true}]}' -F "file=@/tmp/attachment.json" http://127.0.0.${local_address}/_upload/
Time to buy some dog food.
EDIT: As Iām thinking about it, most people send attachments once a week, or to me for troubleshooting. If we cannot find a way to make it work like it use to, all is not lost. With the attachment email, the html file would be an attachment. It isnāt a great solution but it would work until a better way appeared.
Just a clarification, that midclt call spits out the port number, not the IP.
The intent was to catch cases where someone, like @oxyde, has changed the default port 80 to something else, and give you the ability to automagically adjust the port to curl attachments to.
Weāre indebted to you, @joeschmuck. Shame on us if you ever find yourself having to buy a beer whenever youāre in a city where a user of your script livesā¦
When in Santos, Brazil, drinks and steaks are on me.
Iām also trying to send a report html file but I get this error:
āWebSocket connection closed with code=1009, reason='Max message length is 64 kBā
Any ideas how to change this 64kB limit? Works fine with smaller than 64k files.