7

I'm trying to send unix mail (heirloom-mailx) via bcc.

$ mail -V
12.5 6/20/10

My MTA is exim, which sends via Gmail SMTP.

I can execute the following:

echo -e "body" | mail -s 'subject' -b hidden1@server.com,hidden2@server.com visible@server.com

All addresses receive the email, however the bcc is not hidden. i.e. in the email to hidden1@server.com, I still see:

To: visible@server.com
Bcc: hidden1@server.com,hidden2@server.com

How can I make mail send bcc properly?

  • I found this thread on SO: stackoverflow.com/questions/14521280/… – slm Oct 22 '13 at 5:30
  • @slm Thanks. I did come across a few other posts complaining that -b didn't work, but they seemed to suggest that it wouldn't send at all, rather than the problem I have. However, if I don't get a response here, I'll check out some of the other mail programs. – Sparhawk Oct 22 '13 at 5:32
  • Could you name MTA server you use? [sendmail/postfix/exim/...] I think that many servers strip Bcc: headers. – AnFi Oct 22 '13 at 5:36
  • I'm using exim, which sends via gmail smtp. – Sparhawk Oct 22 '13 at 5:39
7

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.

  • Oh! That was surprisingly straightforward. I previously set up gmail smtp with sudo dpkg-reconfigure exim4-config and modifying /etc/exim4/passwd.client. How should I revert these changes, and how do they relate to /etc/nail.rc? – Sparhawk Oct 23 '13 at 10:50
  • @Sparhawk There is no reason to revert your exim4-config changes. nail.rc just configures heirloom-mailx, and in this case you're just configuring it to speak to your local exim a different way (over a TCP connection to localhost vs. running /usr/sbin/sendmail) – derobert Oct 23 '13 at 10:52
1

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.

  • Hi, I'm not really in the position to test this any more, but thank you for answering (+1)! – Sparhawk May 22 '18 at 4:33
  • @Sparhawk: that's okay, I do test all my responses :) – woohoo Sep 8 '18 at 15:44
  • I more meant that for me to +1, I really should verify that "this answer is useful [to me]", but since I cannot, I gave you the benefit of the doubt. – Sparhawk Sep 8 '18 at 23:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.