4

I'm referencing my original post in which I was asking a question about argument placement pertaining to $2 $3 etc, and eventually ${@:2}. It was mentioned that there are better methods to encode email attachments.

Note, I used uname -or to figure out 2.6.32-400.26.3.el5uek GNU/Linux.

I used the command within a bash script to attach a file to an email, and have it in a couple other scripts as well. However, a few of our machines do not even support uuencode, so what are some better options for attaching files to emails than uuencode?

2

I prefer using mpack to send attachments as MIME

as in:

mpack -s "message" file email@example.com

Name

mpack - pack a file in MIME format Synopsis

mpack [ -s subject ] [ -d descriptionfile ] [ -m maxsize ] [ -c content-type ] file address ... mpack [ -s subject ] [ -d descriptionfile ] [ -m maxsize ] [ -c content-type ] -o outputfile file mpack [ -s subject ] [ -d descriptionfile ] [ -m maxsize ] [ -c content-type ] -n newsgroups file Description

The mpack program encodes the the named file in one or more MIME messages. The resulting messages are mailed to one or more recipients, written to a named file or set of files, or posted to a set of newsgroups.

1

You know I find that the following works just fine for files in either TEXT or binary:

 mailx -s SUBJECT -a FILE1 -a FILE2 ... USERNAME

It basically does the MIME encoding automatically and.....even M$ Outlook does the right thing with such a message.

0

If missing uuencode, this perl hack does pretty much the same thing.

Credit goes to Perl Monks site

perl -ple"BEGIN{ $/=\45} $_ = pack 'u', $_" file
  • The question is about avoiding use of uuencode. The back-story is that a MIME-compliant solution is being sought. – roaima Jul 12 '17 at 22:12
0

You could 7z or zip or tar.wz or similar to get a compressed list of files.

Then the compressed list of files could be converted to hex. Use od hd or xxd:

$ xxd -p compressedfile.7z > ToBeMailedFile

Send the file attached to your email.

Convert back the file:

$ xxd -p -r ToBeMailedFile > compressedfile.7z

Expand the file to the list of files.

As HEX pass every web limitation of characters allowed, the file will pass.
As the list of files is compressed before being sent, there is a gain of size.
The compressed file could be also encrypted. Several diferent tools could be used to process the data. Only the conversion of HEX to BIN needs xxd. So, freedom of tools.

  • 1
    xxd is less efficient; it requires 103% more space than the input, vs only 37% more for uuencode and 35% for base64. Demo: i=/bin/dash o=/dev/stdout ; wc -c $i <(uuencode $i $o) <(uuencode -m $i $o) <(xxd -p $i) | head -n -1 – agc Sep 23 '17 at 7:33
  • @agc You may be correct; however: The question specified that uuencode was not available: better options for attaching files to emails than uuencode? – Arrow Sep 24 '17 at 3:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.