How to attach two files in unix script

Hi,

My script has to send 2 files as a separate attachment(Note : files to be sent without zipping) to the specified email id.

Below code was used but it is not attaching the file as expected instead the file contents are displayed in the body of the email.

Kindly,help with your thoughts.

Thanks in Advance.
Meva

If you have mutt on you system it's as easy as:

mutt -a $File1 -a $File2 -s "attachement" abc@xyz.com < Hi

mutt is not available in the system :frowning:

---------- Post updated at 12:34 AM ---------- Previous update was at 12:10 AM ----------

any other options please....

Try if this works..uuencode your attachment files to single file and mail it..

uuencode File1 File1 > attachment_list
uuencode File2 File2 >> attachment_list

mail -s "Reports attachment" myaccount@yahoo.com < attachment_list

Its not working :frowning: the problem that am facing is that the files are not emailed as separate attachments but the contents of the files are displayed in the email.

---------- Post updated at 01:31 AM ---------- Previous update was at 01:10 AM ----------

my requirement is to send the files as separate attachments....in a single mail.

hmm..It did work for me using the above method with multiple attachments in a single email..maybe it would take sometime to have the email in the inbox..anyway this is not the issue here. Are you sure that the attachments are appended (>>) to a single file..? Give us more input if possible.

File 1

aa bb cc

File 2

aa bb cc

If the below code is used

( cat Hi; uuencode "$File1" "$File1"; uuencode "$File2" "$File2") | mail -s "attachment" abc@xyz.com 

then the email body looks as given below

whereas my requirement is that the files to be attached to the email and the body of email should only have the "Hi" as its text.

Kindly let me know ur thougths.
Thanks in Advance.
Meva.

did you try as suggested in post #4 ?

Yes....but it dint work as expected.....the file contents are available in the body of the email and they are not reffered as a separate attachment.

Make sure that the client you use to open an read the email, doesn't have an activated option to put attachement as 'inline text' (i think there is such an option in Thunderbird for example).

Can you please let me know i how can i implement through script for sending an email with two attachments.

I have tried your code as well which works fine except for one thing. Assuming 'Hi' is not a file, you could use echo to instead of cat.

( echo Hi; uuencode "$File1" "$File1"; uuencode "$File2" "$File2") | mail -s "attachment" abc@xyz.com

As suggested by ctsgnb there could be problem in your email client. However can you post your full code..

This is my code

#! /bin/ksh
export EMAILLIST="abc@xyz.com"
cd /home2/data
File1=`ls -lrt *_Accepted.* | tail -1 | awk '{print ($9)}'`
File2=`ls -lrt *_Rejected.* | tail -1 | awk '{print ($9)}'`
echo $File1
echo $File2
SUBJECT="Two Attachment Email"
BODY="Kindly refer the attachment" > /home2/data/email_body.txt
# send an email using /bin/mail
(cat /home2/data/email_body.txt; uuencode "$File1" "$File1"; uuencode "$File2" "$File2") | mail -s "$SUBJECT" $EMAILLIST

Expected Result:

Actual Result:

File1=`ls -lrt *_Accepted.* | tail -1 | awk '{print ($9)}'`
File2=`ls -lrt *_Rejected.* | tail -1 | awk '{print ($9)}'`

could be shorten

File1=`ls -rt *_Accepted.* | tail -1`
File2=`ls -rt *_Rejected.* | tail -1`
echo $File1
echo $File2

are useless (except for interactively controlling the variable have correctly been assigned but echo $File1 $File2 would do the work as well

You could also have a look at this thread, maybe you are experiencing the same kind of problem.
Give a try to the following :
run your script, but change the email address, send it to some external mail address like something@gmail.com adress or any other mail provider, and check how you get your attachment (attached or inline text ?).

I think your script is ok, i suspect the problem is on the reception-side.

The attachment comes as an inline text to my lotus email id. But my requirement is to send it as an attachment.....

Ok but did you try to send the mail to an external mail like someone@yahoo.com or someone@gmail.com ?
and check wether you also get it inline ?

Maybe your server does not allow attachement sending and put it inline ?
Have you ever been able to send an attachement in the past ? (not by using your script, but just by sending it normally)

It looks like your uuencode program is just copying the file as-is, can you check this by doing a uuencode from the command line, you should see something like this:

 $ cat file1
aa bb cc
 
$ uuencode file1 file1
begin 644 file1
)86$@8F(@8V,*
`
end

I tried sending the attachment to email like someone@yahoo.com or someone@gmail.com and am getting it as expected i.e. the files are attached to the email.

But even i tried sending mails to my lotus id manually with two attachments and am able to view the two files as an attachment.Am facing issue when i send it as an attachment through script to my lotus ID.

This demonstrate that the mail you have generated is correct so that it is not the source cause of your problem.

The cause of your problem should be a faulty configuration somewhere in the transfer and/or reception part.

Next question is : when sending your mail to external address, does it go through the same SMTP server than when sending to your Lotus Notes ?

Or is the SMTP server setup with some special rules for the mails whose destination is internal to the society (Lotus Notes) ?

Or is your Lotus Notes Client configured a specific way ?
Are your client and server version up to date ? (maybe missing some patch containing MIME conversion fix ?)

so do we need to write script for MIME conversion? i have a sample script which is used for MIME conversion but that script can be used to send only one attachment :frowning: ....