How to attach a file in Linux mail command


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to attach a file in Linux mail command
# 1  
Old 12-04-2008
How to attach a file in Linux mail command

How to attach a file in Linux mail command

Hi Guys,

Is there any way to attach a file in Linux mail command without using "uuencode"?

i.e.

Code:
file=/a/b/c/d/file.txtmail -s "Giga aks" abc@123.com <<HDoc`uuencode $file $file 2>/dev/null`HDoc
Here, I don;t want to use 'uuencode' command but want $file to be sent in the email as an attachment.


Image Image
#2 (permalink)


Also, when I'm putting the below code (PSee inside `` backquotes) i.e. calling uuencode withing a for loop inside another parent for loop, something strange is happening.

Quote:
`for comp in $(ls -c Directory); do echo $comp;echo ===========; for file in $(find Directory/$comp -type f); do uuencode $file $file 2>/dev/null; done ; done`
Instead of showing each component in the email body and attaching the files under each $comp (a subfolder), this command is making a .txt file of the echo statement (except for the first iteration) i.e. for (echo $comp and echo ============Image and attaching it in the email.

I want the output like:
---------------------------------------------------
HTML Code:
subfolder1===========<path1>/file1 <path1>/file2 <path1>/file3subfolder2===========<path2>/file4 <path2>/file5
---------------------------------------------------

Where, subfolder[12] are 2 folders inder Directory folder and path[12] are 2 different path which will be shown in the attachments/attached files in the email. and file[12345] are the files under those subfolders.

Note: Subfolder[12] and "===========" line under it should come in the email as simple text but the files under that should be shown as attachments under each subfolder[?] (which i think in using Linux Mail command is not possible as you have to configure your outlook email appliation).

Doesn't matter if I get the file[12345] in my email ...all together as attachments..as anyone can easily see the <path?> of a file[?] making a feel that this file is at that path. But, by using the above command within ``(backquotes)... what Linux is doing is:

Im getting only the following in the email body as text data :
---------------------------------------------------
HTML Code:
subfolder1===========
---------------------------------------------------

and
the below things are showing up as attached files... including the echo statement for 2nd subfolder2 and ========== line.

<path1>/file1 <path1>/file2 <path1>/file3

subfolder2
===========
<path2>/file4 <path2>/file5



If you want to try ... just create a folder Directory using another folder which contains some sub folders and files under that... and you'll get to know what i want to achieve.

I can provide more information in case anyone needs.
Thanks-



# 2  
Old 12-05-2008
Use the search function of the forum. This get's asked very often.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Unable to attach a .txt file or .log file to mail and mailx command

Hi, I am trying to attach a .log file or .txt file to mail command to send an email once my ksh script executed. I am unable to use mutt command as it has been not installed and i am not supposed to install it. I have tried many ways by googling which has not helped me to succeed. Here is my... (5 Replies)
Discussion started by: Samah
5 Replies

2. UNIX for Advanced & Expert Users

Attach a document in mail using sendmail command

Hi Guys, May i know how to attach a document using sendmail command in Linux platform.... :confused: (2 Replies)
Discussion started by: Santosh101
2 Replies

3. Shell Programming and Scripting

I need to attach a file in Linux SHELL Scripting

Hi Geeks, I'm trying to write a script to display the errors in a HTML table format and also it should attach the file and it should display the table in the body of the email. Well i wrote the script successfully and i have got the result, but either table is displaying in the email but not... (2 Replies)
Discussion started by: naren nandale
2 Replies

4. Shell Programming and Scripting

How to attach multiple file to send mail command

Hi, i want color effect on mail as well as multiple attachment.I have code but this code is used for single attachment. I am unable to attach more than one file.:wall: I want to send two attachments -ahmed.csv and ahmed1.csv . Sample content: <html> <body> <b> Hi...</b> </body> </html> ... (1 Reply)
Discussion started by: AhmedLakadkutta
1 Replies

5. Shell Programming and Scripting

Attach file in mailx command

Hi I want ot send a mail with aatach a file for this i have tried mailx -s "COMPLETED: deal.sh" -a /usr/local/bin/test.out me@nowhere uuencode /usr/local/bin/test.out /usr/local/bin/test.out | mailx -s "COMPLETED: deal.sh" me@nowhere but of command is not working. so is there any... (0 Replies)
Discussion started by: Himanshu_soni
0 Replies

6. Shell Programming and Scripting

Script to attach file to mail

Hello, I have a .dat file containing one line. I need a script to read that line and make it part of the body and send a mail... Let's say the line is $line. I need the script to send a mail with the body "The last disposal feed is $line". Thanks (4 Replies)
Discussion started by: sfetea
4 Replies

7. HP-UX

How to attach an excel file in a multipart (mime) mail

Hello. I need to send mails from hp-ux with 2 attachments: a text file and an excel file. So I'm composing a mime file which I will pipe to sendmail utility. This works fine if the only attachment is the text file (i use cat command to attach text content). But I have problems with the format... (3 Replies)
Discussion started by: elcampio
3 Replies

8. Shell Programming and Scripting

How to attach a file & send mail thru script

In shell script how can I attach a file and send a mail. suppose if I written like the following way usr/bin/mail 'subject" "mail_id" < file. a mail goes to the mail-id with the content of file.But I want the file to be atttached to the mail.How can I get it.is there any way for this. ... (9 Replies)
Discussion started by: Mar1006
9 Replies

9. Shell Programming and Scripting

Need to attach a txt file while sending mail

Hi, I need to attach a txt file while sending mail thru Unix. Please help me out in this.. -Charan. (9 Replies)
Discussion started by: charan81
9 Replies

10. UNIX for Dummies Questions & Answers

How to attach a file in mail?

Hi, I want to know how to send a mail in unix using mailx or mail or sendmail to send a mail with a file attached. I have read the answers from the other threads but I still don't understand. I want to do it in the command line as well as in script. Can anyone help? DO I need to use... (1 Reply)
Discussion started by: firebirdonfire
1 Replies
Login or Register to Ask a Question