Question : unix mail related question

To send a file as an attachment in the mail,  when I run the below script mailtest.com in the UNIX prompt, it works fine for a text file.

But for an excel file attachement it does send the mail  with attachment. But when I open the attached excel file it says the file is damaged.

Do I need to add some encoding or something?

Any help welcome.

The script mailtest.com looks as below
===============================
(
echo "To:[email protected]"
echo "From:[email protected]"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=12345"
echo "Subject: Test subject"
echo ""
echo "--12345"
echo ""
echo "Test mail body"

echo ""
echo "--12345"
echo "Content-Type: application/excel"
echo "Content-Disposition: attachment; filename=test1.xls"
echo ""
cat test1.xls

) | mailx -t

Answer : unix mail related question

Hi,

You need to modify the script to something similar to below code. But even after this the mail envelope and body containing the attachment you create will display as text will not add to the message envelope. So you wont be able to get the excel file as an attachment. This is because the mailer already creates an envelope and separates  it from the content by adding an empty line in between.

If you want to get the content as text and the excel file as attachemnt try this line instead:

( echo "Text Content"; uuencode example.xlsx example.xlsx ) | mailx -s "test xlsx" [email protected]


Cheers,
K.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
(
echo "To:[email protected]"
echo "From:[email protected]"
echo "MIME-Version: 1.0"
echo "Content-Type: multipart/mixed; boundary=\"--12345\""
echo "Subject: Test subject"
echo ""
echo "--12345"
echo ""
echo "Test mail body" 
echo ""
echo "--12345"
echo "Content-Type: application/octet-stream; name=\"example.xlsx\""
echo "Content-Transfer-Encoding: base64"
echo ""
base64 example.xlsx
echo ".") | mailx -s "Test XLS" [email protected]
Random Solutions  
 
programming4us programming4us