User login

Capture all sent mail locally with Postfix

For development, you don't want any e-mail sent to the outside world, but you do want to be able to see all mail your sites or application try to send. Here is a configuration of Postfix to do that.

The trick is to BCC everything to a local user, and discard without error any other sending.

This is based on several guides and Q&As online but well, none of them worked for me, so here's exactly what i did (minus all the missteps).

If Postfix is already installed, you can sudo dpkg-reconfigure postfix to make certain it is configured for Local only, or if you don't have Postfix yet choose the same options after sudo apt-get install postfix.

Then:

sudo vi /etc/postfix/main.cf

In main.cf add:

transport_maps = hash:/etc/postfix/transport
always_bcc = root@localhost

Not sure if it's necessary, but i read that Postfix prefers to not actually deliver mail to root. So my aliases has a line to use my own account instead of root:

sudo vi /etc/aliases

# See man 5 aliases for format
postmaster:    root
root: ben

sudo vi /etc/postfix/transport

localhost :
onyx :
* discard:

(Where onyx is the name of my computer and is probably not at all needed here.)

This is key, do not forget to create the transport.db file from the transport mapping text file you just edited:

sudo postmap /etc/postfix/transport

And restart Postfix:

sudo service postfix restart

To see what's going on while getting this to work.
tail -f /var/log/mail.log

To see your mail as it gets delivered:

sudo tail -f /var/mail/ben

Searched words: 
Local mail delivery Postfix Ubuntu postfix create transport.db postfix capture all mail for local delivery postfix configure to receive all sent mail at root postfix configure local mail capture

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.