I use the below command to send emails in an Ubuntu server. This seems to attach the testreport.csv file with its full path as the filename.
echo "This email is a test email" | mailx -s 'Test subject' [email protected] -A "/home/dxduser/reports/testreport.csv"
How can I stop this from happening? Is it possible to attach the file with its actual name? In this case "testreport.csv"?
I use mailx (GNU Mailutils) 3.7 version on Ubuntu 20.04
EDIT: Could someone please explain why I got downvoted for this question?
There are multiple different
mailximplementations around, so what exactly works will depend on the version you have installed.However, as a quick and dirty workaround, you can temporarily
cdinto that directory (provided you have execute access to it):The parentheses run the command in a subshell so that the effect of the
cdwill only affect that subshell, and the rest of your program can proceed as before.I would regard it as a bug if your
mailximplementation puts in aContent-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 abase64orquoted-printableencoding of your CSV file is not particularly hard, but you have to know what you are doing. In very brief,where obviously you have to have
base64andsendmailinstalled, and probably tweak the path tosendmail(or just omit it if it's in yourPATH).