Today I pointlessly spent 4 hours figuring out a local mail setup for Snow Leopard. This is all readily available in _every_ variation of Linux and it upset me greatly that I could not just send test email to myself. (NOTE: THIS IS NOT HOW YOU CONFIGURE A MAIL SERVER!!! THIS IS FOR DEV PURPOSES ONLY.)
Problem 1. Lack of imap server.
For that I just downloaded dovecot. Setup is pretty straight forward.
./configure --prefix=/usr/local/dovecot
make && make install
cp /usr/local/dovecot/share/doc/dovecot/example-config/dovecot.conf /usr/local/dovecot/etc/dovecot/
Make sure all the right permissions are there:
sudo dscl . -create /Users/_dovecot
sudo dscl . -create /Users/_dovecot UserShell /usr/bin/false
sudo dscl . -create /Users/_dovecot UniqueID 104
sudo dscl . -create /Users/_dovecot PrimaryGroupID 104
sudo dscl . -create /Users/_dovecot NFSHomeDirectory /var/empty
sudo dscl . -passwd /Users/_dovecot ''
Then I edited dovecot.conf and commented out these lines:
22: #!include conf.d/*.conf
Then added:
protocols = imap
ssl = no
default_login_user = _dovecot
default_internal_user = _dovecot
mail_location = mbox:/var/mail/folders/%u/:INBOX=/var/mail/%u
disable_plaintext_auth = no
passdb {
driver = pam
args = login
}
userdb {
driver = passwd
}
I seriously can't be bothered to setup an SSL for a localhost test mail account only but if you do need one Google is your friend.
Save and start dovecot via /usr/local/sbin/dovecot.
All your issues should be logged in /var/log/mail.log
Problem 2. Postfix.
Since my entry into Linux administration I loathed configuring mail servers. Thankfully you can do everything these days via Google Apps and some quick DNS changes. Dealing with spam, relay blocking, users setups, mail clients and etc was an ongoing pita. But to get started with OSX setup was pretty fast.
Create a file /etc/postfix/virtual if you don't have it.
Add something along these lines. All test emails that go to the domains are forwarded to your user account. It is a quick way of setting up multiple emails for testing and replace 'boris' with your osx username.
@whatever.localhost boris
@me.local boris
Generate a virtual.db via 'postmap virtual'
Save and close and start postfix: 'postfix start'
You can now setup your mail to point to localhost and everything should be working. Open terminal and type:
mail boris (or bee@me.local)
test
.
Don't forget the dot on a new line and change boris to your username. Everything should be delivered to your localhost account.
That should be it and if you have serious trouble http://diymacserver.com/ is an awesome reference.
It is also possible to relay everything to Gmail but you need a valid hostname in your postfix (Gmail rejects localhost). I also do a lot of offline development so I don't always have Gmail there to do my email testing. Local setup + Git is an awesome way to stay off the grid and get some work done.
B
No comments:
Post a Comment