Virtual Users And Domains With Postfix, Courier, MySQL And SquirrelMail (Ubuntu 12.10) - 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 (Ubuntu)

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

Share this page:

8 Comment(s)

Add comment


From: Maqsood at: 2013-01-23 12:02:45

Dear Recipient,

I am facing problem while configuring Postfix, I am performing same steps as given in this article. But I am receiving error message while run this commend “dpkg -i postfix_2.9.3-2ubuntu2_amd64.deb postfix-mysql_2.9.3-2ubuntu2_amd64.deb”. I am using Ubuntu 12.10 server edition. Waiting for your nice guidance

From: Anonymous at: 2013-03-01 14:51:16

Nice guidance - why don't you tell us what the error message is so we can see it? :)

From: Rinti at: 2013-08-07 10:52:15

Its a nice post. I have done accurately and its running fine. But I got another problem. that is about vacation responder / auto reply. I got few ways in internet. but none works for me. As I followed your tutorial, I request you to give a tutorial for auto response working with this configuration.

From: at: 2013-05-17 16:44:07

I had to edit /etc/courier/imapd-ssl and set TLS_CIPHER_LIST="HIGH:MEDIUM:LOW" (it defaults to "HIGH:MEDIUM"). Before I did this STARTTLS logins worked (ports 25, 110) but users could not login using SSL over imap (port 993) or pop3 (port 995) and I kept getting the following in the mail log:

couriertls: read: error:14094412:SSL routines:SSL3_READ_BYTES:sslv3 alert bad certificate

I spent days googling this and couldn't find anything, so adding it here in case anyone else encounters the same issue.

From: Anonymous at: 2013-09-04 11:50:44

If you're using logcheck, remove the spaces either side of the equals sign on the sql_select line of /etc/postfix/sasl/smtpd.conf otherwise it won't match the logcheck ignore rule.

From: shai at: 2013-08-03 15:45:11

adduser clamav amavis
/etc/init.d/amavis restart
/etc/init.d/clamav-freshclam restart


/etc/init.d/clamav-daemon restart

From: Didier Misson at: 2013-03-03 03:40:36

Don't forget that mailbox need to be initialize with the "maildirmake" command !

For :


cd /home/vmail



maildirmake sales

chown -R vmail:vmail sales


Thanks for this great HowTo.


From: Michael at: 2013-12-04 09:50:20

Maybe someone else did the same mistake as me. I had pointed for my domain to my own server and got the error message in /var/log/

(mail for <fqdn of mailserver> loops back to myself)... 

I had just deleted the transport entry and the email-server worked fine.