Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Local Mail Server for Lion

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. 🙂


Requirements:

  1. Solid understanding of Terminal.app 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 ftp://ftp.cac.washington.edu/imap

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:

EXTRACFLAGS="$(EXTRACFLAGS) -DMAC_OSX_KLUDGE=1" \


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" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>Label</key>

<string>edu.washington.pop3</string>

<key>ProgramArguments</key>

<array>

<string>/usr/local/libexec/ipop3d</string>

</array>

<key>Sockets</key>

<dict>

<key>Listeners</key>

<dict>

<key>Bonjour</key>

<false/>

<key>SockServiceName</key>

<string>pop3</string>

<key>SockType</key>

<string>stream</string>

</dict>

</dict>

<key>inetdCompatibility</key>

<dict>

<key>Wait</key>

<false/>

</dict>

</dict>

</plist>


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

CONNECTED(00000003)

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

-----BEGIN CERTIFICATE-----

<certificate content in base64>

-----END CERTIFICATE-----

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

SSL-Session:

Protocol : TLSv1

Cipher : AES256-SHA

Session-ID: <something…>

Session-ID-ctx:

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

quit

+OK Sayonara

read:errno=0


Edit the launchd config file for postfix:

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


Add the following:

<key>KeepAlive</key>

<true/>


Remove the following:

<string>-e</string>

<string>60</string>


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-PIPELINING

250-SIZE 10485760

250-VRFY

250-ETRN

250-ENHANCEDSTATUSCODES

250-8BITMIME

250-DSN

250-BINARYMIME

250 CHUNKING


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


Advanced:

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

Posted on Jul 27, 2011 7:54 AM

Reply
20 replies

Nov 15, 2012 4:28 AM in response to etresoft

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!

Nov 15, 2012 7:57 AM in response to simonhyttfors

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.

Mar 17, 2013 5:41 AM in response to etresoft

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?

Mar 17, 2013 6:23 AM in response to theibel

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) 'imap.so' in Unknown on line 0

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


=====================================================================

PHP : /usr/bin/php

Warning: PHP Startup: Invalid library (maybe not a PHP library) 'imap.so' 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 imap.so 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!

Mar 17, 2013 1:12 PM in response to etresoft

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,

Tom

Mar 17, 2013 1:22 PM in response to theibel

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.

Mar 17, 2013 2:37 PM in response to etresoft

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.

Mar 17, 2013 3:59 PM in response to Frank Caggiano

I don't understand your response. In the above post, etresoft demonstrates how to setup a Mac as a mailserver. He's using IMAP to do so, but I can't get IMAP to compile with, or without (???), PHP. I've been reading the faqs.html that came with the imap-2007f package. Unfortunately, they don't seem to have a support community for these issues. Besides, the answers would vary dramatically for every OS and Unix package. That's why I'm here. Clearly, etresoft knows how to setup a mail server, but unfortunately, IMAP is non-functional.


Any suggestions?

Local Mail Server for Lion

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.