Operating System - HP-UX
1827706 Members
2874 Online
109967 Solutions
New Discussion

Send mails with attachments

 
Yogeeraj_1
Honored Contributor

Send mails with attachments

Hello experts,

i need some precious guidelines.

I need to send files (text, compressed, postscript or PDF) as email attachments.

I have an application generating the following parameters which i wish to forward to an email address:
===============================================
$1 Mail destination address
$2 Subject of Message
$3 Text file containing message
$4 Either 'delete' or 'nodelete' for $3
$5 Attach file (Output file which i want to send as attachment)
$6 Either "delete" or "nodelete" for $5
===============================================

After generating these values, my application will be calling a unix shell script.
e.g. (Makes $5 the mail body content.)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
L-9iAS: d05/9iAS/6iserver/reports60/admin/mail>more r60mail.sh
#!/bin/csh -f
# Send mail message using Unix 'mail'.
#-------------------------------------

# Send mail message using 'mail'.
# When attachment exists, send attachment which is report output.
# When attachment doesn't exist, send message file which is notification.
if ($5 == '') then
mail $1 < $3
else
mail $1 < $5
endif

# Delete the message file.
if ($4 == 'delete') then
rm $3
endif
# Delete the attach file.
if ($6 == 'delete') then
rm $5
endif
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I have alread tried to use uuencode:
/usr/bin/uuencode $5 $5 | mailx -m -s $2 $1

Does not help much. The files attached comes out garbled!

It seems like i am having a MIME type issue.
I believe the use of ELM would be most appropriate here.

Anybody who has something working similar to this?

thank you in advance for a reply.

Best Regards
Yogeeraj

PS. i also tried to install "nail". It gives me an error during the make.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
root-L1000 #make
cd . && /depot/nail-9.30/missing autoheader
sh: /depot/nail-9.30/missing: Execute permission denied.
*** Error exit code 126

Stop.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
11 REPLIES 11
T G Manikandan
Honored Contributor

Re: Send mails with attachments

Stefan Farrelly
Honored Contributor

Re: Send mails with attachments


replace mail -x with sendmail, eg;

uuencode /etc/hosts /etc/hosts | sendmail

And it shall come through as an attachment.
Im from Palmerston North, New Zealand, but somehow ended up in London...
T G Manikandan
Honored Contributor

Re: Send mails with attachments

harry d brown jr
Honored Contributor

Re: Send mails with attachments

Yogeeraj,

for i in `echo filename1 filename2 filename3 ...`
do
uuencode $i $i.txt
done|mailx -m -s "test" username@whereever.com


The key is to have the right "suffix" on the uuencode line:

uuencode somefile somefile.pdf

live free or die
harry
Live Free or Die
Yogeeraj_1
Honored Contributor

Re: Send mails with attachments

hello,

my attachment can be of any type!

how do i modify my script for it to work?

Also, if i was to modify the sender name and add a footer to each message sent?
E.g.
***********************************************
The attached document has been autogenerated by CMT applications.

If you are not the addressee indicated in this message (or responsible for delivering the message to the intended recipient), you should not read it, nor copy or deliver this message to anyone. ***********************************************

thank you in advance



Best Regards
Yogeeraj
--------------------------------------------
#!/bin/csh -f
if ($5 == '') then
mail $1 < $3
else
/usr/bin/uuencode $5 $5 | mailx -m -s $2 $1
endif

# Delete the message file.
if ($4 == 'delete') then
rm $3
endif
# Delete the attach file.
if ($6 == 'delete') then
rm $5
endif
--------------------------------------------
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Stefan Farrelly
Honored Contributor

Re: Send mails with attachments


To add a footer first direct the output of your uuencode to a file;

uuencode > /tmp/temp.$$

echo "Disclaimer .....blah blah blah" >>/tmp/temp.$$

Now your file /tmp/temp.$$ has your uuencoded file AND the disclaimer at the bottom.

Now you can send it using sendmail;

cat /tmp/temp.$$ | sendmail

Note, its very difficult to put a subject line on sendmail so try to get away without one.
Im from Palmerston North, New Zealand, but somehow ended up in London...
Rich Wright
Trusted Contributor

Re: Send mails with attachments

I thought I would give my favorite "mail/attach" solution.
#
# Now send report to "sendto" via email
#
mailx -m -s "${subject}" ${sendto} 1>/dev/null << __EOF__
$(cat ${attachment} | ux2dos - | uuencode ${atach_name}.txt)

... Body of message ...
__EOF__

Using this method, you can have as many attachments as you want and put them anywhere in the body of the message. For binary files remove the "ux2dos" conversion.
Shannon Petry
Honored Contributor

Re: Send mails with attachments

I use elm for this, which encodes for you. You have to build an include file for elm, but is relatively easy. I went this route after some problems with winders seats and uuencoded files from HP-UX.

Sniplett from script:
BINDIR=/usr/bin


$BINDIR/touch /usr/local/squid/etc/mailer.txt
echo "[include /var/tmp/proxy_report.$DATE.zip application/octet-stream base64]" >>/usr/local/squid/etc/mailer.txt
$BINDIR/elm -s "Proxy Report" JohnDoe@Nowhere.com
I had lots of problems with sendmail with this, but some say it's easy. Just make sure your version of elm supports attachments.

Regards,
Shannon
Microsoft. When do you want a virus today?
MANOJ SRIVASTAVA
Honored Contributor

Re: Send mails with attachments

Hi Yogee


Here is an link which will help you :

http://www.stokely.com/unix.sysadm.resources/email.html#attachment.link


there are a variety of software like mpack etc which just need a single command to be type to send any type of attachments.


Manoj Srivastava
Andrej Vavro
Frequent Advisor

Re: Send mails with attachments

Hi Yogee,

I had been using this:

(
echo "Subject: Text in the subject line"
echo "Text in email body"

uuencode
) | /usr/sbin/sendmail recipient@comp.com


This works fine. You can add needed extension to to open it with appropriate appl in windows.

Andrej
Yogeeraj_1
Honored Contributor

Re: Send mails with attachments

Thank you everybody for you replies.

I have temporarily done the following modifications to my scripts:
===============================================
...
if ($5 == '') then
mail $1 < $3
else
if (`ls $5|cut -f 2 -d"."` == 'txt') then
echo "`cat $3` \n[include $5 text/plain base64]"|elm -s "$2" $1
else if (`ls $5|cut -f 2 -d"."` == 'pdf') then
echo "`cat $3` \n[include $5 application/pdf base64]"|elm -s "$2" $1
else if (`ls $5|cut -f 2 -d"."` == 'htm') then
echo "`cat $3` \n[include $5 text/html base64]"|elm -s "$2" $1
else
mail $1 < $5
endif
endif
# Delete the message file.
if ($4 == 'delete') then
rm $3
endif
# Delete the attach file.
if ($6 == 'delete') then
rm $5
endif
...
===============================================

Hope that i have not missed out anything.

Best regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)