Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Debian Wheezy) - 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
Trying ::1...
Connected to localhost.localdomain.
Escape character is '^]'.
220 ESMTP Postfix (Debian/GNU)

<-- ehlo localhost
250-SIZE 10240000
250 DSN

<-- quit
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:

9 Comment(s)

Add comment


From: Anonymous at: 2014-02-26 13:13:45


I succesfully installed according to these instructions and almost everything is working fine.

 Only thing which is not working is SMTP authentication. If I try to add account to Outlook outlook just keeps asking password and username for the SMTP server. Auth.log shows this:

 Feb 26 14:58:37 l119 postfix/smtpd[26228]: sql plugin try and connect to a host
Feb 26 14:58:37 l119 postfix/smtpd[26228]: sql plugin trying to open db 'mail' on host ''
Feb 26 14:58:37 l119 postfix/smtpd[26228]: sql plugin Parse the username

 I changed the SMTP port to 587 before that change i did not even get a connection to the SMTP.

Anybody can help me?


From: Kadu Lessa at: 2014-07-27 19:09:24


Have you corrected this problem? How to fixed this? I trying to fix this for a week!


From: Anonymous at: 2013-07-11 21:24:59

I'm stuck at the postfix installation:

bash: mkimapdcert - command not found
bash: mkpop3dcert - command not found

locate mkpop3dcert

Can anyone know what's the catch here?

From: Jidifi at: 2013-11-05 19:31:09

To anonymous:

You have run 'mkimapdcert' and 'mkpop3dcert' commands as root of course ?

From: Jidifi at: 2013-11-05 18:31:11

Excellent tutorial, even for those who have

lilliputian networks.

Everything works fine, but this guide must be

read very carefully to be fully useful.

Mind nevertheless the syntax of the command

"postconf -e" which may differ with some linux distro.

Thanks a lot.




From: Marcus at: 2014-03-09 23:57:08

Great Tutorial you made. I have a small question.

When i ran "tail -f /var/log/" i see many lines saying me:

"amavis[18304]: Net::Server: Ran out of accept retries! "

What could that be?

Best Regards, Marcus 

From: fly at: 2015-01-02 07:27:27

Hello Sir Falko:

This a very good guide to set up my server. and Great thanks to you.

Here I have one problems confused me a lot.

After Finished the steps as you showed, I found when i mailx my users registered in mail database of mysql, it can not automatically generate the folders for users in the path of ../vmail/ . I have checked ,but can not found where is the problem. can you help me ?

Best wishes.


From: schmoove at: 2015-02-04 15:32:36

For anyone updating from Squeeze to Wheezy and getting login failures when connecting to smtp, with errors in '/var/log/mail.log':

"[...]postfix/smtpd[...]: warning: unknown[]: SASL LOGIN authentication failed: no mechanism available"

Double-check your '/etc/postfix/sasl/smtpd.conf', there are slight changes. The tutorial further up this page reflects those changes. They are practically

--auxprop_plugin: mysql

--sql_select: select password from users where email = '%u'

++auxprop_plugin: sql

++sql_engine: mysql

++sql_select: select password from users where email = '%u@%r'

From: heq at: 2015-03-03 02:12:12

After add ipv6 address to mynetworks, postfix will accept relay from squirrelmail,

postconf -e 'mynetworks = [::1]/128'