Virtual Users And Domains With Postfix, Courier And MySQL (CentOS 5.1) - Page 5

Want to support HowtoForge? Become a subscriber!
 
Submitted by falko (Contact Author) (Forums) on Sun, 2007-12-09 18:07. ::

14 Test Postfix

To see if Postfix is ready for SMTP-AUTH and TLS, run

telnet localhost 25

After you have established the connection to your Postfix mail server type

ehlo localhost

If you see the lines

250-STARTTLS

and

250-AUTH PLAIN LOGIN

everything is fine.

[root@server1 ~]# telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
220 server1.example.com ESMTP Postfix
ehlo localhost
250-server1.example.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-AUTH=PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
quit
221 2.0.0 Bye
Connection closed by foreign host.
[root@server1 ~]#

Type

quit

to return to the system's shell.

 

15 Populate The Database And Test

To populate the database you can use the MySQL shell:

mysql -u root -p
USE mail;

At least you have to create entries in the tables domains and users:

INSERT INTO `domains` (`domain`) VALUES ('example.com');
INSERT INTO `users` (`email`, `password`, `quota`) VALUES ('sales@example.com', ENCRYPT('secret'), 10485760);

(Please take care you use the ENCRYPT syntax in the second INSERT statement in order to encrypt the password!)

If you want to make entries in the other two tables, that would look like this:

INSERT INTO `forwardings` (`source`, `destination`) VALUES ('info@example.com', 'sales@example.com');
INSERT INTO `transport` (`domain`, `transport`) VALUES ('example.com', 'smtp:mail.example.com');

To leave the MySQL shell, type

quit;

For most people it is easier if they have a graphical front-end to MySQL; therefore you can also use phpMyAdmin (in this example under http://192.168.0.100/phpmyadmin/ or http://server1.example.com/phpmyadmin/) to administrate the mail database. Again, when you create a user, go sure that you use the ENCRYPT function to encrypt the password:

I do not think I have to explain the domains and users table further.

The forwardings table can have entries like the following:

source destination  
info@example.com sales@example.com Redirects emails for info@example.com to sales@example.com
@example.com thomas@example.com Creates a Catch-All account for thomas@example.com. All emails to example.com will arrive at thomas@example.com, except those that exist in the users table (i.e., if sales@example.com exists in the users table, mails to sales@example.com will still arrive at sales@example.com).
@example.com @anotherdomain.tld This redirects all emails to example.com to the same user at anotherdomain.tld. E.g., emails to thomas@example.com will be forwarded to thomas@anotherdomain.tld.
info@example.com sales@example.com, billing@anotherdomain.tld Forward emails for info@example.com to two or more email addresses. All listed email addresses under destination receive a copy of the email.

The transport table can have entries like these:

domain transport  
example.com : Delivers emails for example.com locally. This is as if this record would not exist in this table at all.
example.com smtp:mail.anotherdomain.tld Delivers all emails for example.com via smtp to the server mail.anotherdomain.com.
example.com smtp:mail.anotherdomain.tld:2025 Delivers all emails for example.com via smtp to the server mail.anotherdomain.com, but on port 2025, not 25 which is the default port for smtp.
example.com

smtp:[1.2.3.4]
smtp:[1.2.3.4]:2025
smtp:[mail.anotherdomain.tld]

The square brackets prevent Postfix from doing lookups of the MX DNS record for the address in square brackets. Makes sense for IP addresses.
.example.com smtp:mail.anotherdomain.tld Mail for any subdomain of example.com is delivered to mail.anotherdomain.tld.
* smtp:mail.anotherdomain.tld All emails are delivered to mail.anotherdomain.tld.
joe@example.com smtp:mail.anotherdomain.tld Emails for joe@example.com are delivered to mail.anotherdomain.tld.

See

man transport

for more details.

Please keep in mind that the order of entries in the transport table is important! The entries will be followed from the top to the bottom.

Important: Postfix uses a caching mechanism for the transports, therefore it might take a while until you changes in the transport table take effect. If you want them to take effect immediately, run

postfix reload

after you have made your changes in the transport table.

 

16 References

Tutorial: ISP-style Email Service with Debian-Sarge and Postfix 2.1: http://workaround.org/articles/ispmail-sarge/

Postfix + Quota: http://vhcs.net/new/modules/newbb/viewtopic.php?topic_id=3496&forum=17

Mail Passwords Encrypted using saslauthd: http://www.syscp.de/docs/public/contrib/cryptedmailpws

 

17 Links


Please do not use the comment function to ask for help! If you need help, please use our forum.
Comments will be published after administrator approval.
Submitted by Anonymous (not registered) on Wed, 2009-03-18 07:46.

Hello. I installed postfix & courier as this HOWTO describes. I also installed Horde/IMP and configured it to use courier at localhost as an IMAP server. I added domains & users to the MySQL table, however, I kept getting authentication errors when logging into Horde. In /var/log/maillog, there were error messages like:

Mar 17 23:33:53 hostname imapd: chdir example.com/webmaster/: No such file or directory

(I've changed the hostname and domain name in the example above, but otherwise that is a cut-and-paste from my log file).

Turns out, the solution was that the directory it's looking for in /home/vhosts isn't created until after the account receives it's first email. It wasn't until after I'd sent a test message (via smtp a.k.a. port 25) to webmaster@example.com that IMAP logins were sucessful.

Hope this saves somebody some grief.

Submitted by Anonymous (not registered) on Tue, 2008-10-14 21:28.

Hi all.

I'd like to know if this kind of configuration can work with roundcube webclient. If yes, is there any guide or how to marge this configuration with roundcube?

 My problem is that i cant find any link between postfix and roundcube's database. Any advice? Where can i start to work on?

Many thx

P.S.: wonderful guide :)

Submitted by Britto (not registered) on Mon, 2008-10-20 13:54.

Yes.

Roundcube is just a webclient  and you should be able to integrate with roundcube.That is nothing to do with this guide and I could be able to do that .

Everything goes well as per this tutorial other than this version of postfix duplicates the mail for multi recipient inboxes. 

 --

Britto

 

 

 

 

 

Submitted by Anonymous (not registered) on Mon, 2008-10-27 14:02.
Can someone give us some hits how to integrate Roundcube with this setup? Where is the link between the 2 databases?
Submitted by Eugene Frakt (not registered) on Thu, 2009-08-27 05:09.
You don't have to link the databases to use Roundcube.  It connects to the mailbox with standard imap, so all you have to do is input the imap settings in the Roundcube config.
Submitted by tccom (not registered) on Mon, 2008-09-15 16:02.

great tutorial Falko,

 this post is to remember all that if you want to use maildrop as local delivery system, the following line must be inserted into "transport" table of our mysql database 'mail':

<domain>,maildrop:

 and then you can customize maildrop with /etc/maildroprc

 

bye

Submitted by ychouloute (registered user) on Mon, 2008-07-14 22:00.

Great article, and the best one I have found so far. 
However,I think that something is missing from the current tutorial (information about setting up maildir). I was getting some directory issues when i telneted on port 143. Then I realized that had to do a maildirmake on /home/vmail/[domain]/user to create the mailbox , then after that it worked just fine. My question now is : will i have to do that for every user? I thought there was a routine that would automatically create the directory after i add a user to the database.

Thanks again for this Article.

Submitted by BlueC (registered user) on Fri, 2008-07-18 15:33.

The following script in /etc/maildroprc will create the users maildir mailboxes automatically and it will also automatically filter anything marked as SPAM to the users' .Junk/ mail folder.

#SHELL="/bin/sh"
VERBOSE=5

# commands and variables for making the mail directories
maildirmake=/usr/lib/courier-imap/bin/maildirmake
mkdir=/bin/mkdir
rmdir=/bin/rmdir
MAILDIR=$DEFAULT

# make the user's mail directory if it doesn't exist
`test -e $MAILDIR`
if ($RETURNCODE != 0)
{
 `$mkdir -p $MAILDIR`
 `$rmdir $MAILDIR`
 `$maildirmake $MAILDIR`
}

# make the .Junk folder if it doesn't exist
JUNK_FOLDER=.Junk
_JUNK_DEST=$MAILDIR/$JUNK_FOLDER/
`test -d $_JUNK_DEST`
if ($RETURNCODE != 0 )
{
 `$maildirmake $_JUNK_DEST`
 #auto subscribe. the following works for courier-imap
 `echo INBOX.Junk >> $MAILDIR/courierimapsubscribed`
}

if (/^X-Spam-Flag:.*YES/)
{
    exception {
        to $DEFAULT/.Junk/
    }
}

Submitted by acoghlan (registered user) on Sun, 2008-04-06 15:29.

This is a really good setup, but if you add greylisting it cuts down substantially more spam.

There is lots of doc around about greylisting, so make your own mind up about the best tool and method, but http://wiki.centos.org/HowTos/postgrey is really easy to follow and gets you going in minutes.

Highly Recommended as an addition to this howto...

Submitted by BlueC (registered user) on Tue, 2008-04-01 14:23.

To save others from scratching their heads for so long like i did:

The maildrop rpm included for download in this tutorial is not compiled with mysql support! If you wish to use maildrop with the setup described here you will need to build your own maildrop rpm according to the instructions here:

http://www.howtoforge.com/installing-courier-imap-courier-authlib-maildrop-fedora-redhat-centos

Chris