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

250-STARTTLS

and

250-AUTH LOGIN PLAIN

everything is fine:

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

Type

quit

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 ('example.com');
INSERT INTO `users` (`email`, `password`, `quota`) VALUES ('sales@example.com', 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 ('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.

 

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:

aptitude install mailutils

To send a welcome email to sales@example.com, we do this:

mailx sales@example.com

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 sales@example.com
Cc:
<-- ENTER
Subject: Welcome <-- ENTER
Welcome! Have fun with your new mail account. <-- ENTER
<-- CTRL+D
root@server1:/usr/local/sbin#

Share this page:

33 Comment(s)

Add comment

Comments

From: Rick Stanley at: 2010-06-10 23:59:47

I wish people would stop tagging every posting with Ubuntu! Most of the postings involved with the installation and configuration of software I have seen tagged with "Ubuntu" can also be done with MANY different Distros, including this one! You would think that there is only ONE Distro available! NOT!!!

Take a look at the top ten Distributions: DistroWatch

From: Anonymous at: 2010-08-11 16:37:17

Did you not notice that distro-specific how-to's are what's created here for some topics? Calm down. This article, and in fact no post on this site claims Ubuntu is the end-all of linux.

From: Mohamed Elsayed at: 2010-11-02 12:36:10

Dear Falko:

 many thanks for this great effort; actually I have installed my mail server before based on Christoph Haas tutorial at http://workaround.org. it was very helpful, and works 100%.

but for my need, there was something missing which is the mailing lists; I wanted to integrate mailman or any of mailing list management SW to be able to create mailing lists (for example sales@mydomain.com) and add the sales users to this list.

it will be perfect if you could complete this part in your great  tutorial which is (as I think) is very important for a many people.

I sent a comment like this to Christoph Haas on http://workaround.org and I noticed that another people also were interested to add this feature to their implementation. 

 

thanks again for you and I hope you can find a time to complete it soon.

 

From: at: 2011-01-24 02:48:07

you could use the forward table, create a user and add all the emails to it

example: create user salesdept@yourdomain.com

and add  the users salesperson1@yourdomain.com

                               salesperson2@yourdomain.com

and etc, this would be all done in the sql table forwards

I would use phpadmin much easier

From: eric.ni at: 2011-09-20 07:20:56

I follow this,and the tables like this:

mysql> select * from forwardings;
+------------------+----------------------------------+
| source           | destination                      |
+------------------+----------------------------------+
| @test.com     | eric@test.com                 |
| test@test.com | eric@test.com,jan@test.com |
+------------------+----------------------------------+
 then i sent a email to test@test.com, only test usr can receive this email. but when i sent a email to a invalid user,eric user can receive a email.

Anyone can help me?

 

From: Trapper at: 2010-10-04 17:24:49

I note that when creating the 6 text files in postfix for mysql parsing that there's a line:

password = mail_admin_password

Is it to be left as is or is the actual password to be used?

I also note the same circumstances with other files later in the howto.

From: Anonymous at: 2010-10-16 03:49:48

It should be replaced with your actual password, in those 6 files and everywhere else.

From: Jaac at: 2011-01-26 10:48:35

And be sure it does not contains any invalid characters like # which will comment out the rest of the line. Because that will get you into troubles with the configuration and give you a hard time locating the source of the problem.

Having the password in between single quotes will probably work, like 'your#Pa$$w0rd'. But i just avoided the problem by not using certain characters.

From: Anonymous at: 2011-02-12 04:30:01

Please make sure that /etc/mysql/my.cnf contains the following line:

vi /etc/mysql/my.cnf

[...]
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
[...]
#bind-address           =127.0.0.1   Is this line shoud be unable comment? 
 

From: blueday at: 2011-12-06 10:46:17

Hello.

 I folowed your guide, all works ok. However, there is a nasty bug somewhere.

 If you create let;s say webmaster@domain.com and set a password domain99 it's possible to get autentificated with passwords like domain.ro, domain, domain12 etc. Basically, if you put anything in the password field starting wirh domain, you get autentificated.

 Can anyone reproduce this issue?

 Thank you,

From: at: 2012-02-02 06:47:47

Note: If you want to use your domain also as a virtual Domain, than 'mydestination' should be only 'localhost, localhost.localdomain'

postconf -e 'mydestination= server1.example.com, localhost, localhost.localdomain'

From: undifined at: 2010-08-30 12:42:58

 for amavis-d:

it is important to order  the /etc/hosts file, the important parts are: ipv6 before ipv4, fqdn before shortname

 # The following lines are desirable for IPv6 capable hosts

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

ff02::3 ip6-allhosts


::1 localhost6.localdomain6 localhost6 localhost.localdomain localhost ip6-localhost ip6-loopback


127.0.0.1 localhost.localdomain localhost


From: Markofealing at: 2010-06-19 17:05:15

Great tutorial however I've seem to have fallen at the last fence!

When I try to login to my e-mail account using SquirrelMail I'm getting the error message "ERROR: Connection dropped by IMAP server." When I type in sales@training.lan.

If I type in an invalid e-mail address I see waiting for moodle3.training.lan before I get the "unknown user or password incorrect" message, which is what I would expect because the account does not exist. The connection dropped message suggests that the account is validated but then SquirrelMail falls-over!

From: at: 2010-06-24 07:51:42

Usually it happens because the Maildir for that email does not exist.

Have you send greeting email for that account?

From: Anonymous at: 2010-06-26 12:58:53

Sure..! Very useful document for Linux Newbie administrator like me, however, i am getting the similar error,

ERROR: Connection dropped by IMAP server.

I followed the steps as explained. Instead of using the user sales i used a new one, following similar steps as for the user sales.

However, i can not log in.

Will you please assist? 

From: Anonymous at: 2010-06-27 22:44:41

Hello, I received the same error.

Anyway, great HOWTO, gotta thank You a lot.

Please, if someone figured it out, let us know.

Thank You once again

From: cejohnsonsr at: 2010-10-04 01:06:46

I saw this error 1 time. I sent a welcome message to the account & the next attempt to login produced a blank page. Does anyone have any idea why this might happen? No matter what account I try to login to, I always get a blank page.

 

Ed

From: johnny at: 2011-03-10 17:20:42

Well after going through this walk through a few times and still getting errors on the particular server I'm using, particularly the Connection Dropped by IMAP when logging into squirrel mail and trouble creating mailboxes under /home/vmail and msc other errors.

 I decided to try a Dovecot setup instead of Courier and have this setup working now. After installing Squirrel mail by itself after the mail setup I still had the Error connection dropped from Squirrel mail and after numerous file checks disabled the sql_pass from Squirrel mail as 1 user suggested and got Squirrel mail up then to fix the final errors displaying in the left side nav column I edited the following:

 /etc/squirrelmail/config_local.php and added the following to the end of the file which I believe had the opening <?php tag but was missing the closing one.

 nano or vim  /etc/squirrelmail/config_local.php

$default_folder_prefix='INBOX.';
$trash_folder='Trash';
$send_folder='Sent';
$draft_folder='Draft';
?>
 

The tutorial I located on the Dovecot setup is located at the link below and I noticed the author even took the time to set up an automated install script which was much appreciated and worked great aside from the fact the password regex patterns were older and did not account for symbols in the password. The links are below, First is to the tutorial, second to the automated install script, Enjoy ;-)

 Full Tutorial ::

 http://library.linode.com/email/postfix/dovecot-mysql-ubuntu-10.10-maverick

Automated Install ::

http://www.palegray.net/projects/automate/pdm/ubuntu-10-10

From: kunci at: 2010-10-08 08:02:11

Hi!

You must insert the

mailbox_transport = virtual

row in the  /etc/postfix/main.cf and delete or insert # the mailbox_command = procmail -a …. line:

vi /etc/postfox/main.cf
# mailbox_command = procmail -a...
mailbox_transport = virtual

From: Anonymous at: 2010-07-20 22:36:18

Al work i can send mail but i can not receive mail. any suggestions?

 

Oh, about the above two. you must make a dir it's in de tutorial you must first send one mail so the dirs wil be created.

From: toopaq at: 2010-08-04 11:01:31

Why do you need the samba package? I suppose for encrypting passwords but not sure.

From: Anonymous at: 2010-07-27 06:06:22

Hi, i have followed the tutorial, and succesfull to login to squirrel and also can send email to another mail server

but when i try to send email from another server to this ubuntu mail server, still the inbox in squirrel is empty, i've tried to use outlook as well but no luck.

i see the mail.log of postfix/local status is sent and delivered to mailboxes..

any idea? thanx a lot

 Irvan

From: at: 2010-08-07 21:25:42

Hi,

Ive used your tutorials before (couple of years back) and they rock! Luckily i have more experience these days. In any case, i followed it exactly and used patience and common sense. Everything works splendid, i've just sent out my first mail to a gmail address and vice versa, and both emails arrived fast.

To reply on some comments below, even if you buy/rent a domain and forward it correctly, e.g.

domain.tld MX 10 server1.example.com.

If your using a home server on your home ISP, they might be blocking the incoming or outgoing ports. Some ISP's even block both. In that case you can have problems with the mails arriving. Do some research about your specific ISP and their mail server policy.

 Also you should definitely check out the logs on your server (e.g. using: tail -f):

  • /var/log/system.log

  • /var/log/mail.log

  • /var/log/mysql.log

  • /var/log/apache2/access.log

Using a server (dedicated/private) at a hosting company usually saves a lot of headaches but your going to have to pay. In some cases you could also choose to pay for a mail forwarding/redirection service which is cheaper.

Hope that helps!

From: Anonymous at: 2010-11-15 16:30:28

thanks, mailbox_transport = virtual really helped ;)

From: Mike at: 2010-11-07 02:17:36

This is a very good and straightforward tutorial. I have spent hours trying to solve this one though. From the mail.log:

 Nov  7 11:43:02 tbpl postfix/proxymap[1626]: warning: connect to mysql server 127.0.0.1: Access denied for user 'mail_admin'@'localhost' to database 'maildb'
Nov  7 11:43:02 tbpl postfix/proxymap[1626]: warning: connect to mysql server 127.0.0.1: Access denied for user 'mail_admin'@'localhost' to database 'maildb'
Nov  7 11:43:02 tbpl postfix/trivial-rewrite[1665]: fatal: proxy:mysql:/etc/postfix/mysql-virtual_domains.cf(0,lock|fold_fix): table lookup problem
Nov  7 11:43:03 tbpl postfix/smtpd[1628]: warning: problem talking to service rewrite: Success
Nov  7 11:43:03 tbpl postfix/smtpd[1624]: warning: problem talking to service rewrite: Connection reset by peer
Nov  7 11:43:03 tbpl postfix/master[1418]: warning: process /usr/lib/postfix/trivial-rewrite pid 1665 exit status 1
Nov  7 11:43:03 tbpl postfix/master[1418]: warning: /usr/lib/postfix/trivial-rewrite: bad command startup -- throttling

 

maildb is the correct name, I changed it from mail in the installation.

 

I can't work out what I doing wrong. Any help appreciated.

 

Mike

From: at: 2010-11-14 05:50:58

My fault for not reading properly!!! I went back to scratch and built the basic server according to Falko BEFORE doing this install and all worked fine. Excellent Tutorial.

 Mike, Australia

From: bob at: 2011-03-04 07:34:47

i have a problem with squirrelmail.. when i try to login, i got this error

ERROR: Connection dropped by IMAP server.

how to solve this problem.

 

From: Talgat at: 2011-03-28 04:34:14

Thanks for helpful tutorial, but I have 1 problem. When I trying to get mail by POP3 i have authentication error. In mail.log I can see that:

 Mar 28 04:20:15 mail pop3d: LOGIN FAILED, user=admin@4image.uz, ip=[::ffff:10.160.123.3]
Mar 28 04:20:20 mail pop3d: Disconnected, ip=[::ffff:10.160.123.3]

Please, Help me!

From: at: 2011-09-17 15:50:04

An script (based on this tutorial) to automate the entire installation for postfix-courier SquirrelMail. 3 minutes for install process. You find this script at http://forum.ubuntu.ro/viewtopic.php?id=11790 (post #10)

From: Anonymous at: 2011-10-19 13:07:02

I have a problem with adding users and domains. I added sales@domain.tld. ( form the tutorial ) and it works just fine, but if I add another domain or another email address, I cannot login.

 I restarted the postfix and the mysql and the courier-imap... but still the same problem.

I am getting this error:

                           ERROR:

ERROR: Connection dropped by IMAP server.

 

Can somebody help me?

From: at: 2012-03-09 23:47:06

This is because domain name is in two places at time, as real and virtual, and it will not work like that.

Edit /etc/postfix/main.cf and remove Your domain name from "mydestination" .

Then restart postfix.

From: Anonymous at: 2012-04-13 10:24:39

Thanks a lot for your tutorial, clear and simple to follow.

From: Alex at: 2012-12-04 10:23:37

Just tried your setup and it's really good. Also in last installation step I changed Squirrelmail to RoundCube which is less difficult in configuration and looks much better.
 
There were no changes to the entire setup except when you started installing Squirrel - I started installing RoundCube. It also has password change plugin and mysql authorization that are enabled in config file.