---
title: 'Setting up MockSMTP on OSX 10.7(Lion) for local PHP development'
url: 'https://maxwesten.nl/blog/articles/setting-up-mocksmtp-on-osx-10-7lion-for-local-php-development'
markdown: 'https://maxwesten.nl/blog/articles/setting-up-mocksmtp-on-osx-10-7lion-for-local-php-development.md'
date: '2012-06-01'
description: "NOTE : This post was sitting in my drafts for way too long (over 7 months now), so I'll just post it in the hopes someone likes it. There could be rough edges here and there, but hey, that's what the contact page is for... ;) Because I tend to do some PHP development on my MacBookPro runnin OSX 10.7(Lion) and want to be able to test the email-functionality, without the system actually sending email to people, I was on the lookout for an easy way to accomplish this in such a way, that I would be able to collect all mail and display both text and HTML versions of it. I found MockSMTP, and it works like a charm. In this post we'll set it up and configure the system to route all mail to MockSMTP, even when it's not running. Install MockSMTP (via the AppStore or download it from their website) Op"
taxonomy:
  category:
    - OSX
    - PHP
  tag:
    - Apple
    - Development
    - OSX
    - PHP
    - Terminal
    - Work
  archives_month:
    - jun_2012
  archives_year:
    - '2012'
---

# Setting up MockSMTP on OSX 10.7(Lion) for local PHP development

[Home](https://maxwesten.nl/)  [Blog](https://maxwesten.nl/blog)  [Articles](https://maxwesten.nl/blog/articles)  Setting up MockSMTP on OSX 10.7(Lion) for local PHP development 

## [ Setting up MockSMTP on OSX 10.7(Lion) for local PHP development](https://maxwesten.nl/blog/articles/setting-up-mocksmtp-on-osx-10-7lion-for-local-php-development)

    1st Jun 2012   [Apple](https://maxwesten.nl/tag:Apple#body-wrapper) [Development](https://maxwesten.nl/tag:Development#body-wrapper) [OSX](https://maxwesten.nl/tag:OSX#body-wrapper) [PHP](https://maxwesten.nl/tag:PHP#body-wrapper) [Terminal](https://maxwesten.nl/tag:Terminal#body-wrapper) [Work](https://maxwesten.nl/tag:Work#body-wrapper)  

> ****NOTE****  : This post was sitting in my drafts for way too long (over 7 months now), so I'll just post it in the hopes someone likes it. There could be rough edges here and there, but hey, that's what the contact page is for... ;)

Because I tend to do some PHP development on my MacBookPro runnin OSX 10.7(Lion) and want to be able to test the email-functionality, without the system actually sending email to people, I was on the lookout for an easy way to accomplish this in such a way, that I would be able to collect all mail and display both text and HTML versions of it. I found MockSMTP, and it works like a charm. In this post we'll set it up and configure the system to route all mail to MockSMTP, even when it's not running.

Install MockSMTP (via the [AppStore](http://itunes.apple.com/app/mocksmtp/id423535515) or download it from [their website](http://www.mocksmtpapp.com))

Open the terminal and enter the following command to reroute all traffic on port 25 to port 1025 on the local system.

```
sudo ipfw add 1025 forward 127.0.0.1,1025 ip from any to any 25 in

```

Edit the Postfix *main.cf* file from the postfix configuration folder:

```
sudo /etc/postfix/nano main.cf

```

Add the following at the end of the file:

```
relayhost = localhost:1025

```

Make sure the line reading `"mydomain_fallback = localhost"` is witten as: `"mydomain_fallback=localhost"` so without the spaces, to prevent any runtime warnings.

In OSX Lion a new version of postfix is installed, so we need an extra file to deliver mail:

```
sudo touch /etc/postfix/submit.cred
sudo nano /etc/postfix/submit.cred

```

Add the following lines:

```
submitcred version 1
localhost|username|password

```

(Note: the username and password can be used literally here, they don't need to match your account credentials!)

Check the maillog in a new terminal tab/window. This monitors new lines written to the logfile. This way you can troubleshoot and see if messages are sent correctly. (Ctrl+C to stop)

```
tail -f /var/log/mail.log

```

Start Postfix and make sure it will restart on system boot: enter in the terminal:

```

sudo launchctl load -w /System/Library/LaunchDaemons/org.postfix.master.plist

```

Afterwards to stop or start the service use:

```
sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist
sudo launchctl unload /System/Library/LaunchDaemons/org.postfix.master.plist

```

Start the MockSMTP application and make sure it is listening on port 1025 (see the status in the bottom of the screen). [ ![MockSMTP Status](https://maxwesten.nl/images/2/8/7/6/b/2876b7b4a7250a23b1597442d9fa76aa2bce7d1d-mocksmtp-listening-for-email.png)](https://maxwesten.nl/user/pages/02.blog/01.articles/setting-up-mocksmtp-on-osx-10-7lion-for-local-php-development/mocksmtp-listening-for-email.png)

Now try to send a testmail:

```
echo "This is the body of a text test-mail" | mail -s "Email test" test@testdomain.dev

```

And all went well, we now have a testmail in our MockSMTP app. [ ![MockSMTP mailmessage](https://maxwesten.nl/images/d/1/0/8/2/d108233a92449a9b65548a08ee5e3bfeb7439476-mocksmtp-email-received.png)](https://maxwesten.nl/user/pages/02.blog/01.articles/setting-up-mocksmtp-on-osx-10-7lion-for-local-php-development/mocksmtp-email-received.png)

Because we used the IP Port Forward, mail sent by any application that tries to use the local SMTP server (localhost:25) or sendmail/postfix will be rerouted to MockSMTP. If the MockSMTP app is not running, mail will be spooled and will be delivered when you run the app again.

Have fun developing...

 [ Previous Article](https://maxwesten.nl/blog/articles/birth-of-robin-westen) [Next Article ](https://maxwesten.nl/blog/articles/the-move-to-statamic)

#### Related Posts

- 100 

     [Easiest local development environment on OSX](https://maxwesten.nl/blog/articles/easiest-local-development-environment-on-osx "Easiest local development environment on OSX")
- 100 

     [The move to Statamic](https://maxwesten.nl/blog/articles/the-move-to-statamic "The move to Statamic")
- 100 

     [Mod\_security settings for Wordpress 3.x](https://maxwesten.nl/blog/articles/mod_security-settings-for-wordpress-3-x "Mod_security settings for Wordpress 3.x")
- 100 

     [Developing in PHP with NetBeans 6.8](https://maxwesten.nl/blog/articles/developing-in-php-with-netbeans "Developing in PHP with NetBeans 6.8")
- 100 

     [Installing xDebug 2.0.4 or 2.1 on OSX](https://maxwesten.nl/blog/articles/installing-xdebug-204-or-21-on-osx "Installing xDebug 2.0.4 or 2.1 on OSX")

[←](https://xn--sr8hvo.ws/%F0%9F%92%95%F0%9F%8E%89%E2%A4%B5%EF%B8%8F/previous)An IndieWeb Webring 🕸💍 [→](https://xn--sr8hvo.ws/%F0%9F%92%95%F0%9F%8E%89%E2%A4%B5%EF%B8%8F/next)

---

## Navigation

- Parent: [Articles](https://maxwesten.nl/blog/articles.md)
- Previous: [The move to Statamic](https://maxwesten.nl/blog/articles/the-move-to-statamic.md)
- Next: [Birth of Robin Westen](https://maxwesten.nl/blog/articles/birth-of-robin-westen.md)
