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?

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
Emile
  • 385

4 Answers4

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.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232
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.

mdpc
  • 6,834
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
steve
  • 21,892
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 07:33
  • @agc You may be correct; however: The question specified that uuencode was not available: better options for attaching files to emails than uuencode? –  Sep 24 '17 at 03:00