How can I bcc with mailx?

heirloom-mailx hardcodes the options to pass to /usr/sbin/sendmail, and unfortunately the ones it passes don't make Bcc: headers work right in exim. That isn't really fixable, without patching and recompiling it. (You need to have it add -t to the arguments, and then either not pass the list of email addresses or alternatively set extract_addresses_remove_arguments = false in your exim config).

There is an easier solution: just have it send via SMTP. You do this by setting the smtp option, and since you've got a local MTA running, you should be able to set it to localhost. You can test like this:

$ mail -S smtp=localhost -s 'test message' -b other@domain.com email@domain.com
la la la
.

If that works, you can put the smtp option in /etc/nail.rc (system-wide) or ~/.mailrc (per-user). Note that nail.rc, with an n, is not a typo.


If using GNU mailx from mailutils package, BCC and CC can be added by using the --append option to add header variables, like so:

$ echo -e "body text line1\nline2\n\nsent at: $(date)" | mailx --append='FROM:Foghorn Leghorn <fleghorn@sender-domain.com>' --append='BCC:recipient1@acme.com' -s "test subject" -- recipient@acme.com mickey@mouse.com minnie@mouse.com

Also note how the above command uses the header variable for the FROM address.