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