I want to attach a log file to an notification email in FreeNAS. As I understand it, I need to manually MIME encode the log file and append it to the body of the email. Has anyone ever done this? I tried putting the log into the body of the email but it is too long.
I did and it did technically work (in gmail), but it’s largely dependent on the email client since it was originally intended for sending file contents as plaintext in the body of an email.
Also, gmail attaches it both unencoded and encoded as a file called noname which I wasn’t a fan of.
Interesting. I’ll keep that in mind. I’ve remote-hosted inline images and brought them in with html, but if uuencode is simpler, I’d be happy to do that instead.
Was your use case an image in a signature? That’s where I’ve had to manually embed images in the past.
I have not dealt directly with the FreeBSD people before. Is that something I should take to them or do I need to figure out who’s specifically maintaining FreeBSD’s mailx package?
Maybe I should just ask FreeNAS to add mutt? I already have an active redmine account with them.
For FreeBSD you’d probably have to propose an actual patch, though you could reach out to the maintainer and try asking nicely. For FreeNAS you could propose the -a feature and make a really good business case and hope whoever makes decisions about feature requests sees as it worth the developer $/time.
If you really want mutt, just install it in a jail. Configuring a jail isn’t inherently intricate, so unless you’re doing something out of the ordinary (maybe like trying to give the jail access to all the log files of the host) it would just be a matter of clicking through the wizard. Having one general purpose jail for random shenanigans so you can install packages at will, access files, snapshot rollback etc is probably not a terrible idea. The jail gives you a safety net to make sure FreeNAS keeps working in spite of you.
I have almost no idea what it would take to support attachments in mailx. Maybe some mimetypes. Maybe all you want is plain text and it’s easy enough. I do have some experience with email attachments (on the receiving end, and in Haskell, so…) so I’d happily help with guidance, code review, and advocating in FreeBSD. The fact that it doesn’t already exist though makes me suspect there are reasonable alternative ways about this, so I wonder how much effort it really is worth.
Oh wait you already got it figured out? Derp. I must have skimmed past the last part of the original post.
The Linux versions of mailx seem to all have an -a option where you just attach a file and that’s it. It makes sense. It’s not like mime is complicated, it’s just long-winded. Unfortunately, FreeBSD’s mailx doesn’t have it.
So the log file was quickly becoming too large so I needed to implement some compression. If the attachment is too large, the message is not received at all.
I’m not sure how best to deal with this since you can’t know the compressed file size before compressing it, and it’s not like you can just head or tail the compressed file to get a portion of it.
What I might do is compress the file, measure the size and then if it needs to be concatenated, cut down the original by percentage (+ some headroom) and then recompress and retest on a loop until it is small enough to email (ideally only taking one iteration). First though, I have to figure out what the actual size limit is and where it’s being limited (sendmail on the box, gmail smtp or on the receiving end).
Here is my current solution which is to just compress the log file. No guarantee that will be enough to get it through though…
And send it in multiple emails? I’m pretty sure it’s hitting max total attachment size, although I could be wrong.
I think knocking the log level down to info might be the best option. I like the idea of having the debug so you get really good forensic detail on the backup, but a 5MB log file for every backup is pretty far into overkill territory.
Yeah I know it’s possible, but I don’t want to introduce any additional dependencies. It’s important that I be able to copy this script onto any system and run it with minimal complications.
Currently the script only requires rclone to be installed/configured, and sendmail to have a functional smtp configuration (and bash to be upgraded in macos).