There are multiple different mailx
implementations around, so what exactly works will depend on the version you have installed.
However, as a quick and dirty workaround, you can temporarily cd
into that directory (provided you have execute access to it):
( cd /home/dxduser/reports
echo "This email is a test email" |
mailx -s 'Test subject' testemail@gmail.com -A testreport.csv
)
The parentheses run the command in a subshell so that the effect of the cd
will only affect that subshell, and the rest of your program can proceed as before.
I would regard it as a bug if your mailx
implementation puts in a Content-Disposition:
with the full path of the file in the filename.
An alternative approach would be to use a different client. If you can't install e.g. mutt
, creating a simple shell script wrapper to build the MIME structure around a base64
or quoted-printable
encoding of your CSV file is not particularly hard, but you have to know what you are doing. In very brief,
( cat <<\:
Subject: test email
Content-type: text/csv
Content-disposition: attachment; filename="testreport.csv"
From: me <myself@example.org>
To: you <recipient@example.net>
Content-transfer-encoding: base64
:
base64 </home/dxduser/reports/testreport.csv
) | /usr/lib/sendmail -oi -t
where obviously you have to have base64
and sendmail
installed, and probably tweak the path to sendmail
(or just omit it if it's in your PATH
).