Configure your virtual machine to deliver email locally (using postfix, cyrus, imap, and sasl)

Avatar-eric-london
Created by Eric.London on 2008-09-17
Tags:
New Comment
 
I do almost all of my development on Centos virtual machines. This allows me to keep my filesystem, databases, and server configurations contained in a separate environment without harming my host operating system (OSX). This morning, I encountered a problem with my email not being delivered properly. I'm assuming this happened because my virtual machine is not a full qualified email server. I figured the easiest solution would be to setup my virtual machine as an IMAP server instead of trying to fight with DNS, static IPs, spam filters, etc. When it comes down to it, all I need is for my emails sent from my web applications to end up in my email client inbox. Here's what I did to get this to work...

1. Ditch sendmail and install postfix. Postfix is much easier to configure; Sendmail is jibberish.

yum remove sendmail
yum install postfix
chkconfig --level 2345 postfix on


2. Install cyrus, my preferred IMAP service. NOTE: SASL will be the authentication method service

yum install cyrus-imapd cyrus-sasl
chkconfig --level 2345 cyrus-imapd on
chkconfig --level 2345 saslauthd on


3. Configure Postfix service

# edit /etc/postfix/main.cf and change this line:
mailbox_transport = cyrus

# most importantly, I added a few domains (work, personal, etc) to the mydestination variable to ensure that mail sent from my server will be delivered locally, instead of leaving my virtual machine. Make sure you add all the corresponding aliases in /etc/aliases. For instance: If you want to receive email sent to wee@blah.com, you'll have to add blah.com to the list of domains in mydestination and add an alias for wee to redirect to your email account name.


4. Configure Cyrus

# set sasl passwords
saslpasswd2 cyrus
saslpasswd2 eric

# Use Cyrus admin tool to configure mailbox
cyradm --user cyrus --server localhost
> createmailbox user.eric
> setaclmailbox user.eric eric all
> quit


5. Add a new IMAP account in your favorite email client. For my setup, I used the IP address of my virtual machine as the incoming mail server address. Now, when mail is delivered from my virtual machines, it is delivered locally and my email client is used to fetch the new messages!

6. To ensure your setup is working properly, you can send a quick email from the command line (on your virtual machine)

date | mail eric@somedomain.com

Comments

 
  • authentication issues
    Created by Eric.London on 2009-01-21
    Funny, I just tried to follow my own procedure to configure my new virtual machine and I could not authenticate using cyradm. I kept getting this error:
    
    cyradm: cannot authenticate to server with  as cyrus
    


    Once I set the password for the cyrus user, I was all set.
    
    $ passwd cyrus
    
    • use guide
      Created by Anonymous on 2011-03-01
      howto for sasl

      http://wiki.lepr-e.com/wiki/index.php/Ubuntu_Smtp_Server
    • encountered another issues
      Created by Eric.London on 2011-06-28
      I once again go the same error, and the fix was to ensure saslauthd was running:

      /etc/init.d/saslauthd start
  • case sensitivity
    Created by Eric.London on 2009-03-26
    When I created a new virtual machine, I encountered some more issues with these packages. In my /etc/aliases file, I added a few entries to point to the same user and ran the newaliases command. Unfortunately mail could not be delivered to the user. After some digging in my configuration files and mail logs, I found that postfix was forcing my usernames to lowercase (my username was "Eric", and it was trying to deliver to "eric"). The quickest solution would be to use all lowercase usernames. Anyone know a better solution for this issue?
  • I'm trying to do something
    Created by Anonymous on 2009-11-29
    I'm trying to do something similar (with postfix+dovecot) and the virtual domain thing seems to work well for me too.

    I was just wondering if you managed to figure out a way to route ALL outbound mail to one local mailbox. I have a large database to test with, and it's full of real email addresses, which I'd rather not send to erroniously.
    • maybe...
      Created by Eric.London on 2009-12-22
      This might help: http://ericlondon.com/configure-your-development-server-deliver-all-mail-locally