API mail.send Attachments Array

Problem/Justification
With the TrueNAS REST API being discontinued, there now appears to be no way that I’ve been able to find to provide attachments to the mail.send call which previously took attachments as an HTTP upload.

With midclt gaining the ability to receive calls via stdin, I would like to propose that the API gain the ability to instead accept an array directly for the attachments setting, in the format used by the REST API.

Impact
This should make it possible for midclt call mail.send to fully replace previously used mail sending methods.

User Story
A user previously using mail.send via the REST API will be able to switch over to midclt by simply moving their attachments array into the call object itself (rather than setting “attachments”: true separately).

For my own use case, this will make it easy to send S/MIME encrypted messages without having to jump through a bunch of extra hoops as I would be able to simply use the output of openssl cms -encrypt to build my attachments and send that, like I used to do using sendmail.

For example:

echo "{"subject":"Test message","to":"user@example.org","attachments":[{"headers":[{"name":"MIME-Version","value":"1.0"},{"name":"Content-Disposition","value":"attachment; filename=\"smime.p7m\""},{"name":"Content-Type","value":"application/pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\""},{"name":"Content-Transfer-Encoding","value":"base64"}],"content":"MIIDDgYJKoZIhvcNAQcDoIIC/zCCAvsCAQAxggK/MIICuwIBADCBojCBmzELMAkGA1UEBhMCR0IxETAP…"}]}" | midclt call mail.send

If I’ve somehow missed the correct way to send attachments now, do please let me know!

The WebSocket API documentation suggests this capability is already present, using the /_upload endpoint. See Jobs — Uploading a File

Looks like you’ve posted a link to your own local NAS there, but I think I know the page you mean — the only example of uploading a file is shown as using curl which surely means it’s part of the REST API that’s being discontinued?

It’s entirely possible I’ve misunderstood, but I’ve found no examples of how to do this using the web sockets API only or ideally midclt which is what I’m specifically hoping to use if possible (since TrueNAS 26 will allow sending a payload via stdin, it seems like it should be able to handle at least smaller attachments at the same time).

I know that someone already made a script for attaching files and sending it per mail for joes multi-report script, but i can’t for the life of me find the post

Sorry about that. I’ve fixed the link.

1 Like

The API docs for TrueNAS 26 and 27 show this means of uploading files to still be in place.

1 Like

You’re probably thinking of the standalone-tn-send-email.py script which may be what I’ll need to use in future — ideally I wouldn’t need to though as mail.send could just be easier to use.

The way that python script works is by essentially reimplementing mail.send by sending messages via SMTP etc. directly rather than going through the API.

yes that’s the one, i really have to save more links and don’t try to remember it all :sweat_smile:

Just tested it and it does indeed still seem to work so I guess I’ve just misunderstood what’s being discontinued, my bad!