2

I did the following in Ubuntu 12.04:

echo "some body" | mailx -s "some subject" [email protected] -- -f [email protected]

it generated a message like this:

To: [email protected]
Subject: some subject
From: [email protected]

Then I updated to Ubuntu 14.04 and now I get

To: [email protected], [email protected], [email protected]
Subject: some subject
From: [email protected]

So, the -f is working no longer, and I get a broken email.

Why is this and how can I fix it?

I am using nullmailer.

I am using bsd-mailx.

$ ls -l $(which mailx)
lrwxrwxrwx 1 root root 23 Okt 23 23:12 /usr/bin/mailx -> /etc/alternatives/mailx
$ ls -l /etc/alternatives/mailx
lrwxrwxrwx 1 root root 18 Okt 23 23:12 /etc/alternatives/mailx -> /usr/bin/bsd-mailx
2
  • The manual of mailx says that -f file is to read mail from an alternate file... not to set the "From:" field. I really do not know if it's a recent change...
    – Rmano
    Jan 16, 2015 at 18:36
  • 1
    @Rmano: yeah, but the -- should cancel processing of command line arguments and forward the following arguments to sendmail/nullmailer
    – mnagel
    Jan 16, 2015 at 22:16

3 Answers 3

1

As a workaround I can set the From: header manually with -a $EXTRAHEADER and drop the -- -f thing:

echo "some body" | mailx -s "some subject" [email protected] -a "From: [email protected]"
1
  • Thanks! This was very helpful, I could not find this workaround anywhere else. Oct 6, 2017 at 20:33
1

It looks like a security patch in early January changed the behavior for --.

From the changelog at https://launchpad.net/ubuntu/+source/bsd-mailx/8.1.2-0.20111106cvs-1ubuntu0.1

bsd-mailx (8.1.2-0.20111106cvs-1ubuntu0.1) precise-security; urgency=medium

  • SECURITY UPDATE: shell command injection
    • Apply OpenBSD patches from Todd Miller (taken from Debian update):
      • 80-remove_T.patch (remove undocumented/obsolete -T option)
      • 81-minus_f.patch (adjust -f processing)
      • 82-expandaddr.patch (fix CVE-2014-7844)
      • 83-nosendmail.patch (make -- work for option parsing suppression)
    • CVE-2014-7844 -- Marc Deslauriers Mon, 05 Jan 2015 11:40:44 -0500

Your workaround is correct, the -a option is best for setting the From header.

I still have a problem where the -f option set the Return-Path header, which I did not have any luck doing with -a. I got this from https://groups.google.com/forum/#!topic/list.postfix.users/0AmocPqLUZo

0

I ended up using /usr/sbin/sendmail (provided by postfix) instead of the mail command that linked to bsd-mailx on my system:

echo -e "Subject:some subject\n\nsome body" | /usr/sbin/sendmail -r "[email protected]" "[email protected]"

Three things to consider:

  • Use -r to specify the return path (and from-address)
  • There is no -s for the subject. Instead, add the Subject: mail header in the printf followed by two newlines \n\n
  • Your echo really needs to output the two newlines, not the characters \n\n, thus you need echo -e

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .