How can I bcc with mailx?

16,339

Solution 1

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 [email protected] [email protected]
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.

Solution 2

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 <[email protected]>' --append='BCC:[email protected]' -s "test subject" -- [email protected] [email protected] [email protected]

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

Share:
16,339

Related videos on Youtube

Sparhawk
Author by

Sparhawk

I like algae.

Updated on September 18, 2022

Comments

  • Sparhawk
    Sparhawk almost 2 years

    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 [email protected],[email protected] [email protected]
    

    All addresses receive the email, however the bcc is not hidden. i.e. in the email to [email protected], I still see:

    To: [email protected]
    Bcc: [email protected],[email protected]
    

    How can I make mail send bcc properly?

    • slm
      slm over 10 years
      I found this thread on SO: stackoverflow.com/questions/14521280/…
    • AnFi
      AnFi over 10 years
      Could you name MTA server you use? [sendmail/postfix/exim/...] I think that many servers strip Bcc: headers.
    • Sparhawk
      Sparhawk over 10 years
      I'm using exim, which sends via gmail smtp.
  • Sparhawk
    Sparhawk over 10 years
    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?
  • derobert
    derobert over 10 years
    @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)
  • Sparhawk
    Sparhawk about 6 years
    Hi, I'm not really in the position to test this any more, but thank you for answering (+1)!
  • scrat.squirrel
    scrat.squirrel almost 6 years
    @Sparhawk: that's okay, I do test all my responses :)
  • Sparhawk
    Sparhawk almost 6 years
    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.