Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Debian Squeeze) - Page 4

12 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




everything is fine:

root@server1:/usr/local/sbin# telnet localhost 25
Connected to localhost.localdomain.
Escape character is '^]'.
220 ESMTP Postfix (Debian/GNU)
ehlo localhost
250-SIZE 10240000
250 DSN
221 2.0.0 Bye
Connection closed by foreign host.



to return to the system shell.


13 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 ('');
INSERT INTO `users` (`email`, `password`, `quota`) VALUES ('', ENCRYPT('secret'), 10485760);

(Please take care that 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 ('', '');
INSERT INTO `transport` (`domain`, `transport`) VALUES ('', '');

To leave the MySQL shell, type


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 or 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 Redirects emails for to Creates a Catch-All account for All emails to will arrive at, except those that exist in the users table (i.e., if exists in the users table, mails to will still arrive at @anotherdomain.tld This redirects all emails to to the same user at anotherdomain.tld. E.g., emails to will be forwarded to thomas@anotherdomain.tld., billing@anotherdomain.tld Forward emails for 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 : Delivers emails for locally. This is as if this record would not exist in this table at all. smtp:mail.anotherdomain.tld Delivers all emails for via smtp to the server smtp:mail.anotherdomain.tld:2025 Delivers all emails for via smtp to the server, but on port 2025, not 25 which is the default port for smtp.


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


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.


14 Send A Welcome Email For Creating Maildir

When you create a new email account and try to fetch emails from it (with POP3/IMAP) you will probably get error messages saying that the Maildir doesn't exist. The Maildir is created automatically when the first email arrives for the new account. Therefore it's a good idea to send a welcome email to a new account.

First, we install the mailx package:

apt-get install mailutils

To send a welcome email to, we do this:


You will be prompted for the subject. Type in the subject (e.g. Welcome), then press ENTER, and in the next line type your message. When the message is finished, press ENTER again so that you are in a new line, then press CTRL+D; if you don't want to cc the mail, press ENTER again:

root@server1:/usr/local/sbin# mailx
Subject: Welcome <-- ENTER
Welcome! Have fun with your new mail account. <-- ENTER
<-- CTRL+D
Cc: <-- ENTER

Share this page:

18 Comment(s)

Add comment


From: at: 2011-03-01 18:01:30

Would love to see PostfixAdmin included in this how-to.

Thanks for the great job, you've saved my butt plenty of times!!!

From: Luciano Talarico at: 2011-12-09 10:10:13


I'm working to build a test lab mailserver based on this guide but with postfixadmin for backend. I'm writing some notes so, when I finish, will try to give my contribute. Best regards.

From: Patricio at: 2011-09-15 16:43:30



I see that  you are using  mysql ENCRYPT function to encrypt the password. Can encrypt using  another hashing function like SHA512 or MD5?

 how can I do that?

 I just search a lot and I did not found nothig




From: at: 2012-05-13 05:52:43

I had a problem with creating these tables due to an error similar to this:-

 ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE=MyISAM' at line 4

This apparently is because TYPE is now depracated and you should use ENGINE instead.


From: Anonymous at: 2013-05-14 16:30:37

to download the good patch version, go to , copy the url of your version and replace the url of the wget line.

 Sorry for my english, i speak french :)

From: Sylvan at: 2013-08-24 10:51:33

Hi!  Why do you make changes to /etc/aliases? As I understand it, when Postfix is set up as you have in this tutorial, all address lookups will be done towards the MySQL databases and not /etc/aliases? When I followed your guide and tried to send a test mail to it bounced with an error of "User unknown in virtual mailbox table".

From: Daniel R Matos at: 2011-03-03 15:22:56

I geting this error. In the mail.err apears: imapd: : No such file or directory

From: Moritz at: 2011-04-20 14:04:49

I have the same error. I can't send a mail to the new mail address. If I send a mail from my normal mail address I get an answer from Mailer Daemon who says that I have a unknown user.

If I send an e-mail to an adress in the forwarding table, there are no problems.

From: Anonymous at: 2013-01-14 19:01:56

I have the same problem. Is there any solution?

authtest -s imaps says:

Authenticated:  (uid 5000, gid 5000)
Home Directory: /home/vmail


postconf -e 'virtual_mailbox_base = /home/vmail'

has no effect :-(

From: Anonymous at: 2013-02-25 01:55:56

I have the same error...No such file or directory :-s

From: Anonymous at: 2013-12-16 05:04:34

chown -R vmail:vmail /home/vmail/

From: at: 2011-03-28 11:04:53

Look closely at step 14 "Send A Welcome Email For Creating Maildir".

After first mail comes to Your accounts, the directories are created and Your problem should be solved.

From: nano91 at: 2011-04-08 14:33:29

when i execute the configtest.php suggested by squirrelmail i do not get any error, but trying to log in i get 'ERROR: Connection dropped by IMAP server.' Already sent a welcome email: root@srv1:~# mailx Subject: Test Welcome EOT root@srv1:~# What does the EOT mean? And why can't i login?

From: Anonymous at: 2011-07-25 10:00:41

Regarding the "ERROR: Connection dropped by IMAP server" please have a look here: and here:

From: Anonymous at: 2012-04-25 10:37:11

When you see  ERROR: Connection dropped by IMAP server The problem is with this table

INSERT INTO `forwardings` (`source`, `destination`) VALUES ('', '');
INSERT INTO `transport` (`domain`, `transport`) VALUES ('', '');

When i don't populate this table everything is ok.

From: edo at: 2013-03-22 11:39:11

You must delete old entry in mysql and type INSERT INTO `transport` (`domain`, `transport`) VALUES ('', ':'); and everything is OK

From: Anonymous at: 2012-06-15 18:38:56

First let me say that this is an excellent start although I have a couple of extra things I will add because of preference.  Thanks!

Regarding the error above, I had the same issue and realized that I had not changed the "mail_admin_password" text in some of the later pages because I had stepped away and finished the installation(s) later.  Once I went back through the install pages and checked (and updated several) of the configuration files all was well.  I did note that some of the details prior to the edit descriptions for these files did not explicitly point out to change this and that was mostly where I would forget.

 But all is good now - Thanks again for a great guide!

From: edoMostar at: 2013-03-26 07:48:29

Which program recommended for entry of new email users (PhpMyadmin,Adminer)? I need something like Phamm-LDAP.