'mailx: "send-mail: illegal option -- a" while attempting to send file attachment

Our production server has been retired and now we are using a hosted system running Redhat GNU/Linux.

We had many scripts using mutt to send file attachments but they're failing now since mutt is not installed on our servers (The sysadmin policy is that mutt is not secure so it will not be installed)

I have tried using mailx but to no avail. When I do

echo "this is my email body"| mailx -s "this is my email subject" "[email protected]" -a "filename.csv"

I get

$ send-mail: illegal option -- a

"filename.csv" exist and it is local to the directory I run the command from. Of course, when I do

mailx -s "this is my email subject" "[email protected]" < "filename.csv"

It works but it embeds the file attachment in the email body. Users do not want that.

What am I doing wrong?



Solution 1:[1]

I figured it out. I simply moved the -a flag before the email address like so

echo "this is my email body"| mailx -s "this is my email subject" -a "filename.csv" "[email protected]"

It worked just fine.

Solution 2:[2]

uuencode filename.csv filename.csv | mailx -s "this is my email subject" "[email protected]"

Or, if you want to clump text and an attachment together, then

echo "this is my email body" | cat -<(echo uuencode filename.csv filename.csv) | mailx -s "this is my email subject" "[email protected]"

Solution 3:[3]

I came across the same problem, use -A instead of -a. It worked for me.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user2773648
Solution 2
Solution 3 aman ali