I'm trying to play with the postfix after queue. Basically, I want to see if I can modify outgoing email. (I'm not interested at all in incoming email). I did the following (based on http://www.postfix.org/FILTER_README.html) :

  1. launch ec2 on aws (ubuntu 16.04)
  2. install postfix
  3. created filter with user filter
  4. modify the master.cf by adding the -o content_filter=filter:dummy

    smtp inet n - y - - smtpd -o content_filter=filter:dummy

  5. add the filter service definition at the end of the master.cf file

    filter unix - n n - 10 pipe flags=Rq user=filter null_sender= argv=/home/ubuntu/run_filter.sh -f ${sender} -- ${recipient}

  6. Send email using

    echo "hello world" | mail -s "second message" ...@gmail.com

But the filter is not called. And the email is sent without any change.

It seems like I'm missing something very basic. If someone can help, thanks!

  • 1
    Did you check the log? – 030 May 22 '17 at 19:13
  • 2
    When you do that echo "hello world" | mail -s "second message" ...@gmail.com, what happens in /var/log/mail.log ? – Miloš Đakonović May 22 '17 at 19:18
  • Have you reloaded Postfix? Again: show the logs! – Marc Stürmer May 27 '17 at 8:32

It could be that your php.ini isn't referencing the correct path to sendmail.

You can check your php.ini file or apache logs to confirm this.

Alternatively, you can use the absolute path instead:

echo "Subject: test" | /usr/sbin/sendmail test@example.com

you can also confirm the registered path from command line:

which sendmail

Good Luck :)

  • Maybe you could explain why trying that would make a difference. – chicks May 24 '17 at 18:57
  • 1
    Sorry, As you can see I'm quite new around here. I'll edit my answer now with further clarification. – Max Coates May 25 '17 at 15:24
  • Thanks Max. That's a much nicer answer. Good luck to you too. :) – chicks May 25 '17 at 23:42

I may be wrong as I don't know exactly your setup, but I think that mail does not send messages through smtp. You can check postfix logs, if your message is received via postfix/smtpd or via postfix/pickup.

You can configure mail to use smtp I think, depends what mail you have installed (mailx, nail etc).


This answer doesn't answer directly your question, but could help you more on long term.

When I have an application that I expect to do something, I am using tracing tools like strace, tcpdump/wireshark, perf, systemtap.

In your case, because I expect mail to connect via a TCP or at least an Unix socket to send the email, I would run it under strace.

echo "hello world" | strace -f -e network mail -s "second message" ...@gmail.com

-f = follow child processes too.

-e network = trace only network related system calls. You may use -e file to see which files are used. For more details see strace(1) man page

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.