Operating System - HP-UX
1819681 Members
3540 Online
109605 Solutions
New Discussion юеВ

how to send attachments in a folder

 
SOLVED
Go to solution
tom quach_1
Super Advisor

how to send attachments in a folder

Hi All,

Thanks in advance for your help.
i am able to use mailx to send mail with attachments (2).
What i would like to do is to be able to sending mail from a folder with 6 or 7 files ( the folder name and file names are dynamic and changing daily)as attachments.

Can someone help me please?

Regards,
Tom
7 REPLIES 7
Mel Burslan
Honored Contributor
Solution

Re: how to send attachments in a folder

to accomplish this, you need to be able to somehow determine the foldername as it also is variable. There must be some characteristic of this name, creation time or something.

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

FOLDERNAME=/Some/Folder
cd $FOLDERNAME
for file in `ls`
do
uuencode $file $file >> $TEMPFILE
done

cat $TEMPFILE | mailx -m -s "Subject line here" user@domain.com

rm $TEMPFILE #if you wish

note that, this will not deliver the files to the recipient as a single folder as there is no such concept in exchange servers, only files can be atached, not folders. So, the recipint will get a message with multiple attachments.

I tested with 2 files and it works
________________________________
UNIX because I majored in cryptology...
tom quach_1
Super Advisor

Re: how to send attachments in a folder


Thanks Mel Burslan FOR YOUR HELP

#!/sbin/sh
TEMPFILE=/tmp/tomtest
if [ -a $TEMPFILE ]
then
rm $TEMPFILE
fi

FOLDERNAME=/tmp/perf*
cd $FOLDERNAME
for file in `ls`
do
uuencode $file $file >> $TEMPFILE
done

cat $TEMPFILE |mailx -m -s "testing" tquach@sunrider.com


--somehow this line
uuencode $file $file >> $TEMPFILE
it appended all contents of files to this file $TEMPFILE
an so there is no attachment.
the " perf* " is a dynamic folder.
Would you please advice.

Thanks,
Tom
Mel Burslan
Honored Contributor

Re: how to send attachments in a folder

appending to the same file is the nature of the script. each individual attachment will have a start and end descriptor, which any exchange server will understand and separate at the receiving end.

I have tested this script with a folder with 2 files in it and and I have received, on my exchange server account, 2 files attached to an email message.

and the random number makes your temp file a different name every time it runs. Of course there is a chance of getting the same random number, so, you are strongly encouraged to run the "rm" command once you are done with a batch of files to remove the temp file.
hope this helps.
________________________________
UNIX because I majored in cryptology...
Steven E. Protter
Exalted Contributor

Re: how to send attachments in a folder

Zip them up first, any way you want.

Then use this script to send them as an attachment:

http://www.hpux.ws/mailfile2

Do take note of the fact that smtp relay programs that are not properly patched can and have made it impossible to send attachments. If my script doesn't work (this is my improvement on an HP doc), check that your smtp relay or mail engine is up to date.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
tom quach_1
Super Advisor

Re: how to send attachments in a folder

Thanks Mel Burslan & steven,

Mel, your script works. The reason, it did not work before, because the size of file hit the limit on my Unix server. tested it with many smaller files and it works as expected. Tested the same file using yahoo account sent to my exchange account and received it without a problem. So my Unix server is the source of the problem.
Does anyone know how to increase the size limit to send out mail from hpux.

Thanks,
Tom
Arunvijai_4
Honored Contributor

Re: how to send attachments in a folder

If you use sendmail, there is an option in /etc/mail/sendmail.cf to increase mail size,

# Maximum message size (option MaxMessageSize): #
# #
# This option restricts the maximum message (in bytes) that sendmail will #
# accept from a remote system. If a message larger that this limit is #
# originated form the local system, the message will be truncated to the #
# limit. #
# #
# To enable this feature uncomment the line: #
# #
# O MaxMessageSize=100000 #
# #

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
tom quach_1
Super Advisor

Re: how to send attachments in a folder


Hi-Arun:

Change it to 15Mb but it still won't send out mail larger than 4.5Mb
I am using mailx.
Any help appreciated.

Regards,
Tom