Mailx command to send attachment file

Hi,

I need to send a attachment which has space in the file name as: "ABC Data Extract.txt" which is present in the location /home/projects/txt

i am using

/home/projects/scripts
mailx -s "Sub" email_id "/home/projects/txt/ABC Data Extract.txt"

but i am not getting the attachment.

try the below

uuencode path/'ABC Data Extract.txt'  "ABC Data Extract.txt" |mailx -s "subject" xyz@abc.com

From man mailx :

       -a file
              Attach the given file to the message.

Try

mailx -s "Sub" email_id -a "/home/projects/txt/ABC Data Extract.txt"
DIR_TEMP=/home/projects/scripts
emal_sbjct_txt='ABC DEF'
Email_body.txt --> ABC
emal_id='xyz@abc.com'
dest_desc=/home/projects/txt
rpt_nm=ABC Data Extract.txt

cat "${DIR_TEMP}/Email_body.txt" |  mailx -s "${emal_sbjct_txt}" ${emal_id} -a ${dest_desc}/"${rpt_nm}"

the attachment is not getting delivred.
Also the email id are not coming correctly.

If it's not correct, then what is it?

Is it a script you posted? If yes, remove or comment out this (it makes no sense there): Email_body.txt --> ABC

You need to quote the value you're assigning to a variable if the value contains whitespace(s). Try

rpt_nm="ABC Data Extract.txt"

If the command still fails, the order of the mailx options might matter, in this case try (note option -a *before* the email address):

cat "${DIR_TEMP}/Email_body.txt" |  mailx -s "${emal_sbjct_txt}" -a ${dest_desc}/"${rpt_nm}" ${emal_id}

If everything fails, post your script and error messages you get.

1 Like

-a does not exist on standard unix to my knowlege except maybe the very last release...
and may not be for attach <file> e.g. here a Debian:

     -a      Specify additional header fields on the command line such as "X-Loop: foo@bar" etc.  You have to use
             quotes if the string contains spaces.  This argument may be specified more than once, the headers will
             then be concatenated.

That is why we insist so much on you giving the shell you use, and the architecture / OS and OS release...

After changing the order in mailx it worked.
Thanks you