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.

[LEFT][LEFT] #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 ============ 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-

[/LEFT]
[/LEFT]

1 Like

Use the search function of the forum. This get's asked very often.

1 Like