Operating System - Linux
1752664 Members
5606 Online
108788 Solutions
New Discussion

How to send multiple files as an attachment in single mail through SUSE Linux Script

 
SOLVED
Go to solution
Narendra1979
Occasional Contributor

How to send multiple files as an attachment in single mail through SUSE Linux Script

Hi,

We want to send multiple files as an attachment in single mail through SUSE Linux Script. But looks like there is no "m" option in SUSE Linux..

Please find the script which we are using in HP-UX as below but same is not working in SUSE Linux

TEMPFILE=/tmp/temp$RANDOM
if [ -a $TEMPFILE ]
then
rm $TEMPFILE
fi

FOLDERNAME=/logs
cd $FOLDERNAME
for file in `ls`
do
cat $file | ux2dos | uuencode $file >> $TEMPFILE
done
cat $TEMPFILE | mailx -m -s "Subject`hostname`" narendra.uttekar@xyz.com
rm $TEMPFILE

Thanks,

Narendra

 

3 REPLIES 3
Steven Schweda
Honored Contributor

Re: How to send multiple files as an attachment in single mail through SUSE Linux Script

> We want to send multiple files as an attachment [...]

   Do you want to send multiple files as _an_ attachment, or multiple
files as _multiple_ attachments (in one message)?

   Programs like Info-ZIP Zip or "tar" (usually used with gzip or bzip2
(or similar programs) for compression) can be used to package multiple
files into one, and then one attachment can carry the whole collection.

   If you want multiple attachments in one message, then you should
probably look for a real MIME e-mail client program.

Matti_Kurkela
Honored Contributor
Solution

Re: How to send multiple files as an attachment in single mail through SUSE Linux Script

The -m option in HP-UX is described in the HP-UX mailx(1) man page as:

-m
Do not add MIME header lines Mime Version, Content Type & Content Encoding to the header 
information while sending mails.

Your script is using a legacy method of sending email attachments: the MIME standard for handling different character sets, attachments and other modern email features has existed since year 1993.

At least on a SuSE SLES 12 SP2 system I had available to me for testing, the SuSE mailx command always adds the MIME header lines and cannot be prevented from adding them. On the other hand, it has option -a for attaching files to messages.

The script is also using "ux2dos" which does not exist in SuSE: the equivalent would be "unix2dos".

Let me suggest an alternative script for you:

#!/bin/sh

# script settings here
FOLDERNAME=/logs

# create a list of "-a <filename>" options for SuSE mailx cd "$FOLDERNAME" for LOGFILE in * do ATTACHMENTS="$ATTACHMENTS -a $LOGFILE" done mailx $ATTACHMENTS -s "Subject $(hostname)" narendra.uttekar@xyz.com

Using the MIME attachments instead of legacy uuencoding allows the attachments to be opened successfully in both Windows and Unix/Linux systems alike: SuSE mailx is smart enough to detect that the files you're attaching are text files, so it automatically uses the text/plain MIME type to attach them. Then, the receiving email program can automatically convert the line endings if necessary for the destination system, just like it already does for the regular email text, so running the attachments through unix2dos should no longer be necessary.

MK
Steven Schweda
Honored Contributor

Re: How to send multiple files as an attachment in single mail through SUSE Linux Script

> [...] so running the attachments through unix2dos should no longer be
> necessary.

   Info-ZIP Zip and UnZip also offer options to adjust line endings
(Zip: -l, -ll; UnZip: -a, -aa), so you could probably shed
ux2dos/unix2dos with that method, too.

   As usual, many things are possible, and it may help to begin with
your actual requirements, rather than asking how to implement a
particular "solution" to a problem.