Emailed Excel workbook appears broken after being attached

4

I have worked a bit with an email attachment issue, and can now send attachments through email, through a script.

When the email comes in, I double-click the attachment, and Excel 2016 opens, with a dialog reading: We found a problem with some content in 'attachment.xlsx'. Do you want use to try to recover as much as we can? If you trust the source of this workbook, click Yes. I click Yes, it works. If I open the original file from the same server through Samba, it works fine. Only after it's gone through email does it appear to not be perfect.

What can I do to get rid of this dialog, so the recipient does not see it constantly? I plan on running the script weekly, with a new Excel file each week.


The command that runs: (uuencode /path/to/file.xlsx file.xlsx; echo $BODY) | mail -r me@example.com -s "Subject Line" user@example.com

The file size is increased by 1 byte after being emailed. In this case, it's now 18738 bytes after being emailed. The SHA256 hashes are different between the two files.

Canadian Luke

Posted 2019-06-14T20:08:36.547

Reputation: 22 162

Answers

2

uuencode definitely changes the file. You would need to uudecode on the other end to get the original file back.

To prove this to yourself run this:

uuencode /path/to/file.xlsx file.xlsx > testfile.xlsx

Do you get a valid Excel file?

Now:

uudecode /path/to/testfile.xlsx testfile.xlsx > testfile2.xlsx

Is testfile2.xlsx a valid Excel file?

SOLUTION: You can either decode the file on the other end or use a modern mail attachment function: You can add the heirloom-mailx package to Debian to add the -a attachment feature.

HackSlash

Posted 2019-06-14T20:08:36.547

Reputation: 3 174

To use this method you would need to decode the file on the other end. This is not the way you should be sending attachments. This was how they sent attachments in the 1970's before MIME types. – HackSlash – 2019-06-14T21:04:25.037

Nevermind, this works if I manually specify "heirloom-mailx -a ..." – Canadian Luke – 2019-06-14T21:14:54.123