Running a Mail Server

From OS X Scientific Computing

Jump to: navigation, search


Contents

How to Set Up the Mail Server on OS X

Apple OS X since 10.3 comes with postfix, a more secure drop-in replacement for sendmail. This permits you to run a mailserver on your computer. Think twice about doing so, because once you activate a mailserver on a computer, you introduce a whole new set of security concerns, primarily because nefarious evildoers can break in and turn your computer into a spam relay. If your university or employer provides a systemwide mailserver that is professionally administered, you are most likely better off using that. But if you insist on having your own, here are some hints to get it going.

Setting up Postfix

===Edit the file /etc/postfix/main.cf=== and make the following changes:

  • Enter a value for myhostname: myhostname = yourcomputer.yourdomain.edu This is the full host and domain name for your computer.
  • Enter a value for myorigin (Optional): myorigin = department.domain.edu The myorigin parameter specifies the domain that locally-posted mail appears to come from.
  • Enter a value for mynetworks_style. The default setting is subnet but it is perhaps safer to use mynetworks_style = host, which allows mail to be sent only from your computer. (Subnet permits mail to be sent from any computer sharing the same subnet, so if you really can trust all of them, stick with the default. I'll tell you how to use ssh tunneling to send mail from your laptop anywhere in the world via your server computer, and this can be done with mynetworks_style = host.
  • Uncomment the line inet_interfaces = localhost

Edit the file /etc/hostconfig

and change the appropriate line to MAILSERVER=-YES-

Fix the broken Launchd script

Edit the file /System/Library/LaunchDaemons/org.postfix.master.plist, to remove a couple of spurious lines, so that you are left with:


<?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>org.postfix.master</string>
        <key>Program</key>
        <string>/usr/libexec/postfix/master</string>
        <key>ProgramArguments</key>
        <array>
                <string>master</string>
        </array>
                <key>RunAtLoad</key>
        <true/>
         <key>OnDemand</key>
                         <false/>
</dict>
</plist>

Start postfix either by rebooting or by doing the following:

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


Setting up POP3 and IMAP

You will probably also want to compile and install pop3 and imap to have a fully-functional mail server. Here is how to do that:

Download the software from the UW-imap website:

http://www.washington.edu/imap and unpack it.

In the uw imapd source directory,

edit src/osdep/unix/env_unix.c and change mailsubdir to "Library/Mail/IMAP" (keep the double-quotes).

Issue the command

mkdir -p ~/Library/Mail/IMAP .

Issue the command

make oxp PASSWDTYPE=pam SSLTYPE=unix .

Install the compiled daemons, and enable PAM authentication,

issuing the commands

sudo mkdir -p /usr/local/libexec
sudo cp  imapd/impad   /usr/local/libexec/imapd
sudo cp  ipopd/ipop3d   /usr/local/libexec/ipop3d
sudo cp /etc/pam.d/login /etc/pam.d/imap
sudo cp /etc/pam.d/login /etc/pam.d/ipop3d
sudo cp /etc/pam.d/login /etc/pam.d/imaps

Create Launchd plist files

for imap, pop and so on in /Library/LaunchDaemons. They all work basically the same way. Here is my imapd plist file (I called it edu.washington.imap3.plist to adhere to Apple's apparent nomenclature for these things):

<?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>Disabled</key>
        <false/>
        <key>Label</key>
        <string>edu.washington.imapd</string>
        <key>OnDemand</key>
        <false/>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/local/libexec/imapd</string>
        </array>
        <key>Sockets</key>
        <dict>
                <key>Listeners</key>
                <dict>
                        <key>Bonjour</key>
                        <false/>
                        <key>SockServiceName</key>
                        <string>imap</string>
                        <key>SockType</key>
                        <string>stream</string>
                </dict>
        </dict>
        <key>inetdCompatibility</key>
        <dict>
                <key>Wait</key>
                <false/>
        </dict>
</dict>
</plist>

It should be obvious how to make any others you might want.

Start the imapd

with the command sudo launchctl load edu.washington.imap3.plist.

Check to see if it works

with the command

telnet 127.0.0.1 143  

The 143 means it operates from port 143. You should see output like this:

Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4REV1 LITERAL+ SASL-IR LOGIN-REFERRALS STARTTLS AUTH=LOGIN] 
localhost IMAP4rev1 2004.357 at Thu, 7 Jul 2005 20:08:12 -0700 (PDT)

You can now set Apple's Mail.app program to recognize your mail server

by using 127.0.0.1 as both your incoming mail server and you SMTP (outgoing) mail server. Assuming you want IMAP, create an IMAP account and enter those values, along with port 143 (or the SSL version - it doesn't matter since you aren't sending any passwords out over the nextwork. If you log in from afar, you will likely want to use the SSL version or an SSH tunnel.

Another Option: Postfix Enabler

If you would rather just pay someone else to do this for you, one option is Postfix Enabler. It is essentially a GUI interface for the above procedure, although I think it creates an older-style StartupItem instead of a Launchd script.

Personal tools