Previous 1 2 Next 20 Replies Latest reply: Apr 2, 2013 9:29 AM by etresoft
etresoft Level 7 Level 7

Since the User Tips aren't ready yet, I thought I would go ahead and post my definitive guide to getting a local mail server running on Lion. This is meant to be a follow-on to my post on Local Web Server for Lion. Setting up a mail server is a bit more complex and not always required, so I put this document into its own post. I tried to use mail server in Lion Server, but found this process easier.



  1. Solid understanding of and how to run command-line programs.
  2. Basic understanding of mail servers.
  3. Basic usage of vi. You can substitute nano if you want.
  4. Xcode and basic understanding of how to build software form the command line.


Lines in bold are what you will have to type in at the Terminal.

Replace <your local host> with the name of your machine. Ideally, it should be a one-word name with no spaces or punctuation. It just makes life easier.

Replace <your short user name> with your short user name.

Replace <your login password> with your password.


Here goes... Enjoy!


Download the UW IMAP software.

Connect to

Login as guest

Copy the file imap-2007f.tar.gz to your Desktop


Expand the archive with

tar zxvf imap-2007f.tar.gz


Fix the makefile. Open imap-2007f/Makefile and comment out line 422 that reads:



Build the software with:

make oxp SSLDIR=/usr SSLCERTS=/System/Library/OpenSSL/certs


Create a place to store the server:

sudo mkdir -p /usr/local/libexec


Copy the server into place:

sudo mv ipopd/ipop3d /usr/local/libexec


Create a PAM authentication module:

sudo cp /etc/pam.d/ftpd /etc/pam.d/pop


Create a self-signed certificate:

sudo openssl req -new -x509 -nodes -out /System/Library/OpenSSL/certs/ipop3d.pem -keyout /System/Library/OpenSSL/certs/ipop3d.pem -days 3650


Create launchd config files

sudo touch /Library/LaunchDaemons/edu.washington.pop3.plist

sudo vi /Library/LaunchDaemons/edu.washington.pop3.plist


Enter the following content:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "">

<plist version="1.0">




























Do the same for /Library/LaunchDaemons/edu.washington.pop3s.plist. changing Label to pop3s and SockServiceName to pop3s


Load the launchd config files:

sudo launchctl load -w /Library/LaunchDaemons/edu.washington.pop3.plist

sudo launchctl load -w /Library/LaunchDaemons/edu.washington.pop3s.plist


Test your POP server:

openssl s_client -connect localhost:995


depth=0 <certificate stuff…>

emailAddress=<the e-mail address you used for the certificate>

verify error:num=18:self signed certificate

verify return:1

depth=0 <certificate stuff…>

emailAddress=<the e-mail address you used for the certificate>

verify return:1


Certificate chain

0 s:<certificate stuff…>

   i:<certificate stuff…>


Server certificate


<certificate content in base64>


subject=<certificate stuff…>

emailAddress=<the e-mail address you used for the certificate>

issuer=<certificate stuff…>

emailAddress=<the e-mail address you used for the certificate>


No client certificate CA names sent


SSL handshake has read 1037 bytes and written 328 bytes


New, TLSv1/SSLv3, Cipher is AES256-SHA

Server public key is 1024 bit

Secure Renegotiation IS supported

Compression: NONE

Expansion: NONE


    Protocol  : TLSv1

    Cipher    : AES256-SHA

    Session-ID: <something…>


    Master-Key: <something else…>

    Key-Arg   : None

    Start Time: 1311510626

    Timeout   : 300 (sec)

    Verify return code: 18 (self signed certificate)


+OK POP3 localhost 2007f.104 server ready

user <your short user name>

+OK User name accepted, password please

pass <your login password>

+OK Mailbox open, 5 messages


+OK Sayonara



Edit the launchd config file for postfix:

sudo vi /System/Library/LaunchDaemons/org.postfix.master.plist


Add the following:




Remove the following:




Restart postfix master:

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

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


Test your SMTP server:

telnet <your local host> 25

Trying fec0:0:0:fea9::1...

Connected to <your local host>.

Escape character is '^]'.

220 pele.local ESMTP Postfix

EHLO <your local host>

250-<your local host>


250-SIZE 10485760









telnet> quit


Construct a test message:

From: <your short user name>@<your local host>

To:  <your short user name>@<your local host>

Subject: This is a local test


This is a local test of the mail system.


Send your test message:

cat test.txt | sendmail -t


Setup Apple Mail to connect to:

Incoming Mail Server: <your local host>

User Name: <your short user name>

Password: <your login password>


Outgoing Mail Server SMTP: <your local host>

Use only this server: checked



Port: 995

Use SSL checked

Authentication: Password


Check your e-mail in Apple Mail. Accept the certificate.

MacBook 2007 (white), Mac OS X (10.7), + iMac 27" + iPad + MacBook Pro
  • bompi Level 1 Level 1

    Cool tutorial.


    It helped me to find out why I couldn't log to the imap server : PAM definition of imap has changed from Snow Leopard to Lion.


    Thx. !

  • Mister Ramac Level 1 Level 1

    Unfortunately, the test of pop server does not work:

    connect: Connection refused



    If someone can help...

  • simonhyttfors Level 1 Level 1

    I am very sorry to comment here, but the thread about web servers was locked. Anyway I followed that tutorial, and it was great! It was exactly what I was looking for and it really helped me out! Thanks for that. But I tried to change the root file of the web server but I didn't have the permission, I changed the permissions and changed the root file, but it just stays the same. I've waited for some time now, to see if it updated, but it won't. It just stays the same even though I've changed the file. It's like Apache is looking for another file than what i changed.

    I edited the file index.html in /Library/WebServer/Documents. From the beginning it looked as the HTML in it said, so I am pretty sure that is the root file for the server. Thank you again!

  • etresoft Level 7 Level 7

    Did you re-load the page? I don't think that whatever problem you are having is necessarily related to my instructions. I suggest starting your own question and explaining the problem. You should reference my User Tip so people will know what actually did. There are lots of people who can help you get it fixed. You shouldn't have to wait for me just because I get notifications about this thread.

  • theibel Level 1 Level 1

    This is a great tutorial!  I wish I had found it last week.  Do you have some suggestions for compiling IMAP in PHP 5.4.12?  I have tried to get it to compile for a couple days now and it just won't take.  I can't get passed several errors and frankly, I haven't found anyone that can.  I've tried suggestions from here on Apple and made many attempts from various Linux forums.  Do you have a tutorial for compiling IMAP with PHP?

  • theibel Level 1 Level 1

    etresoft, here's some of the code when trying to compile the IMAP:


    Toms-iMac:imap UserName$ make test


    Build complete.

    Don't forget to run 'make test'.


    PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) '' in Unknown on line 0

    PHP Warning:  PHP Startup: Invalid library (maybe not a PHP library) '' in Unknown on line 0



    PHP         : /usr/bin/php

    Warning: PHP Startup: Invalid library (maybe not a PHP library) '' in Unknown on line 0


    PHP_SAPI    : cli

    PHP_VERSION : 5.4.12

    ZEND_VERSION: 2.4.0

    PHP_OS      : Darwin - Darwin Toms-iMac.local 12.2.0 Darwin Kernel Version 12.2.0: Sat Aug 25 00:48:52 PDT 2012; root:xnu-2050.18.24~1/RELEASE_X86_64 x86_64

    INI actual  : /Users/UserName/sourcecode/php-5.4.12/ext/imap/tmp-php.ini

    More .INIs  : 

    CWD         : /Users/UserName/sourcecode/php-5.4.12/ext/imap

    Extra dirs  :

    VALGRIND    : Not used


    TIME START 2013-03-17 13:15:43


    SKIP Bug #31142 test #1 (imap_mail_compose() generates incorrect output) [tests/bug31142_1.phpt] reason: imap extension not available

    SKIP Bug #31142 test #2 (imap_mail_compose() generates incorrect output) [tests/bug31142_2.phpt] reason: imap extension not available

    SKIP Bug #32589 (crash inside imap_mail_compose() function) [tests/bug32589.phpt] reason: imap extension not available

    SKIP Bug #35669 (imap_mail_compose() crashes with multipart-multiboundary-email) [tests/bug35669.phpt] reason: imap extension not available

    SKIP Bug #40854 (imap_mail_compose() creates an invalid terminator for multipart e-mails) [tests/bug40854.phpt] reason: imap extension not available

    SKIP Bug #44098 (imap_utf8() returns only capital letters) [tests/bug44098.phpt] reason: imap extension not available

    SKIP Bug #45705 test #1 (imap rfc822_parse_adrlist() modifies passed address parameter) [tests/bug45705_1.phpt] reason: imap extension not available


    As you can see above, I get the build to complete, but it fails the test all the way down.  I have in the php.ini extenstions, and I've tackled all the other issues that have come up, pcre, utf8 and so on, but still no joy.  Any advice would be helpful.  Thank you!

  • etresoft Level 7 Level 7

    PHP cannot build anything. I'm not really sure what you are doing there.

  • theibel Level 1 Level 1

    Thanks etresoft!  After configuring IMAP in the /../..php-5.4.12/ext/imap by phpize, I've tried to get it to complete the "make test" and the results are above.  I've tried many configurations and this is as far as I can get.  I've read ideas here on Apple and numerous other sites, but no luck.


    Do you have any ideas?

    Thank you,


  • etresoft Level 7 Level 7

    Can you explain to me what PHP and IMAP have to do with each other? IMAP is a web server. PHP is a scripting language. There is apparently some kind of IMAP interface in some version of PHP source that you have found, but that is wholly unrelated to getting IMAP running. You are really going in the wrong direction here.

  • theibel Level 1 Level 1

    I'm not understanding your question.  When anyone compiles PHP, they include (--with-imap) or they exclude the imap configuration variables.  It must be configured with:  ./configure --with-imap=/usr/local/lib --with-kerberos --with-imap-ssl=/usr


    After the configuration, I get the green light to run "make"


    creating libtool

    appending configuration tag "CXX" to libtool

    configure: creating ./config.status

    config.status: creating config.h

    config.status: config.h is unchanged


    Then when I run make, I get:


    48 warnings and 1 error generated.

    make: *** [php_imap.lo] Error 1


    Upon reviewing the /../php-5.4.12/ext/imap director, I notice that I don't have an "imap.lo" file, but I have an "imap.loT" file.  Figuring it was just a compile mistake, I rename imap.loT to imap.lo and the compile builds successfully.


    Build complete.

    Don't forget to run 'make test'.


    Then when I run the "make test", I get the results I posted above.


    Is this helping?  I think I may have multiple problems here, but at this point, I've guessed for 2 days now and come up empty.  I'm not making any customizations, just following the instructions.


    Thank you.

  • Frank Caggiano Level 7 Level 7

    You have to have PHP's c-client libraries compiled and installed for PHP to IMAP to work.


    But I think you might be misunderstanding what IMAP in PHP does. It allows PHP to communicate with an IMAP server it does not tun PHP into an IMAP server or enable IMAP on your system. If that is what you are trying to do.

  • etresoft Level 7 Level 7

    Why are you compiling PHP? I know nothing about that nor would I even attempt it. Compiling PHP is nothing but a big old can 'o worms sure to cause grief.

  • theibel Level 1 Level 1

    I've never heard, or read, anyone mentioning that IMAP can run as a stand alone program.  Is that what you're saying???


    I'm compiling PHP to upgrade it from 5.3.15, to 5.4.12 so I can combine it with the Apache server 2.4.4 and MySQL 5.6.13.  So I can use it all as an e-commerce web server.

  • Frank Caggiano Level 7 Level 7

    No IMAP is a protocol that a Mail Server can choose to support. So if you want to respond to IMAP requests you need a mail server that supports it.

Previous 1 2 Next