Setting up a Linux virtual mail server

Updated version available

I've created an updated version of this for Etch with the newer Postfixadmin release (2.2.0). See here for it. This 'version' should work, hence I'm not removing it.

Introduction

This page details how to setup an email server on Linux that is capable of handling multiple domains and users. Users can collect mail via pop3 or imap and change their password via a web interface. Administrators can add/edit/remove domains or users through a web interface.

Background

For some time, I've been setting up and installing mail servers, but they've nearly always been for one (or small number) of domains. To do this, I've just used Postfix and flat files to store the relevant information. This has worked well, but isn't very easy for non-technical people to edit/view, and requires my attention should a password need changing, or a new address adding etc - in short it doesn't scale (because I don't) very well.

Needless to say, a customer requested essentially an email solution for multiple domains, with Postfix on Linux. Although we could have just given them my 'standard' Postfix and Cyrus setup, some sort of administrative interface was needed which a non-Linux administrator could use.

Initially I planned to write my own web interface, knowing in advance that Postfix can use PostgreSQL as a data source (see this).

This could have been at least a number of days worth of work, and I didn't really want to re-invent the wheel if I could help it.

Thankfully I then discovered the following - Postfixadmin.

Keywords

Postfix, Courier, PostgreSQL, PostfixAdmin, POP3, IMAP.

History

  • 2007/04/30 - Updated for Ubuntu Dapper (previously Debian Sarge-ish) - change to php5, PostgreSQL 8.1, fixed postfixadmin download url,

About PostfixAdmin

When I first came across PostfixAdmin, I wasn't sure if it would be usable by us, as it had it's own not-quite-open license. Upon reading the license, it was possible to read it that you didn't have permission to run the software, so I emailed the lead developer who replied stating that it would be changing to a GPL license shortly, and I should have no worries about using it.

PostfixAdmin is written mainly for use with MySQL, therefore it's necessary to apply a patch in order to get it to support PostgreSQL (more on this later).

I've taken some screenshots of PostfixAdmin which can be found here

Installing Apache (v2)

Apache and PHP need installing.....

apt-get install apache2
apt-get install libapache2-mod-php5
apt-get install php5-pgsql

Installing PostgreSQL

This is again, very easy :

apt-get install postgresql-8.1

(PostgreSQL 8.1 is available in Ubuntu Dapper; if you prefer to use e.g. the 7.4. version as shipped with Sarge you may do so).

Installing Postfix

This is a simple case of :

apt-get install postfix
apt-get install postfix-pgsql

apt will ask various questions, choose to configure for an internet site.

Installing PostfixAdmin

This is not quite as straight forward, unfortunately ...

cd /var/www/
wget http://kent.dl.sourceforge.net/sourceforge/postfixadmin/postfixadmin-2.1.0.tgz
tar -zxf postfixadmin-2.1.0.tgz
cd postfixadmin-2.1.0

(Note: The wget download of postfix admin didn't unextract cleanly, but the a Firefox download did.).

Patching PostfixAdmin

This should only be necessary for version 2.1. The current version in subversion (soon to be 2.2) does not need this patch.

cd /var/www/postfixadmin-2.1.0
wget http://troels.arvin.dk/db/postfixadmin/postfixadmin-arvin.patch
cat postfixadmin-arvin.patch | patch -p1

I didn't experience any difficulties, and the patch cleanly applied.

Setting up PostgreSQL

su - postgres
export PGDATABASE=template1
echo "CREATE USER postfix WITH PASSWORD 'something'" | psql 
echo "CREATE USER postfixadmin WITH PASSWORD 'something'" | psql
echo "CREATE USER vacation WITH PASSWORD 'something'" | psql 
echo "CREATE DATABASE postfix OWNER postfixadmin" | psql 

Of the users created, postfix has read-only access to the database (as postfix only ever queries the data store), postfixadmin has the ability to update/create/remove entries.

You may wish to edit /etc/postgresql/.../pg_hba.conf to restrict/lock down access to the database e.g. I normally have only the following enabled :

local   all         postgres                          ident sameuser
host    all         all         127.0.0.1         255.255.255.255   md5

Which allows the 'postgres' user local access through ident authentication, which is needed for cron scripts. The second line, allows anyone to connect locally on 127.0.0.1 if they can provide a valid username and password.

If you're using PostgreSQL 7.4, you will also need to edit /etc/postgresql/..../postgresql.conf and enable TCP/IP connections by ensuring there is a line reading :

tcpip_socket = true

Creating the PostgreSQL database structure

The patched Postfixadmin source tree contains a file called DATABASE_PGSQL.TXT which contains the necessary database schema. I therefore use something like the following :

export PGHOST=localhost
export PGUSER=postgres
export PGPASSWORD=secret
export PGDATABASE=postfix
cat DATABASE_PGSQL.TXT | psql

(If you're fussy, a psql < DATABASE_PGSQL.TXT could be used instead, allowing you to remove an unecessary 'cat')

Configuring Postfix

Now the database schema is loaded, we need to make some changes/additions to the Postfix configuration to allow it to read some of it's configuration out of PostgreSQL.

These are the changes I added the following into my /etc/postfix/main.cf :

# Custom stuff for postfix admin
virtual_alias_maps = pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf
# What (virtual) domains Postfix does mail for
virtual_mailbox_domains = pgsql:/etc/postfix/pgsql/virtual_domains_maps.cf
# Where Postfix finds the mailbox for $user@$domain
virtual_mailbox_maps = pgsql:/etc/postfix/pgsql/virtual_mailbox_maps.cf
# Incase we are a backup MX server for any domains :
relay_domains = pgsql:/etc/postfix/pgsql/relay_domains.cf
# Where all mailboxes are under 
# (i.e. resulting in /var/mail/vmail/$user@$domain/).
virtual_mailbox_base = /var/mail/vmail
# Quota limit...
virtual_mailbox_limit = 51200000
virtual_minimum_uid = 1001
virtual_transport = virtual
# What UID is used to deliver/own the mail files 
# (needs to link in with courier config)
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001

# This is necessary for the virtual 'stuff' above to be used
local_transport = virtual
# This tells Postfix to accept mail for users 
# which appear in the virtual_mailbox_maps above.
local_recipient_maps = $virtual_mailbox_maps



Next, create a directory to store the PostgreSQL / Postfix .cf files, namely :

mkdir /etc/postfix/pgsql

And then populate the files with appropriate stuff (this is lifted off from the Postfix wiki, just convered to pgsql specific stuff)

virtual_alias_maps.cf

user = postfix
password = something
hosts = localhost
dbname = postfix
query = SELECT goto FROM alias WHERE address='%s' AND active = true

virtual_domains_maps.cf

user = postfix
password = something
hosts = localhost
dbname = postfix
#query = SELECT domain FROM domain WHERE domain='%s'
#optional query to use when relaying for backup MX
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = false and active = true

virtual_mailbox_limits.cf

# Used for QUOTA!
user = postfix
password = something
hosts = localhost
dbname = postfix
query = SELECT quota FROM mailbox WHERE username='%s'

virtual_mailbox_maps.cf

user = postfix
password = something
hosts = localhost
dbname = postfix
query = SELECT maildir FROM mailbox WHERE username='%s' AND active = true

relay_domains.cf

user = postfix
password = something
hosts = localhost
dbname = postfix
query = SELECT domain FROM domain WHERE domain='%s' and backupmx = true

At this point it's probably best doing :

tail -f /var/log/mail.log &
postfix stop
postfix start

And seeing if there are any errors reported.

You will need to create /var/mail/vmail and ensure it is chown 1001 /var/mail/vmail, else you'll encounter delivery problems.

Setting up the Postfix Admin Web Interface

Visit : http://myserver/postfixadmin-2.1.0 and you will be displayed with a welcome page; click on 'setup' and you'll get a list of things to install/fix.

cd /var/www/postfixadmin-2.1.0
cp config.inc.php.sample config.inc.php
vi config.inc.php

You'll need to edit the following in the config.inc.php file :

$CONF['postfix_admin_url'] = "http://myserver/postfixadmin-2.1.0";
$CONF['postfix_admin_path'] = "/var/www/postfixadmin-2.1.0";
$CONF['database_type'] = "pgsql";
$CONF['database_host'] = "localhost";
$CONF['database_user'] = "postfixadmin";
$CONF['database_password'] = "something";
$CONF['database_name'] = "postfix";
$CONF['database_prefix'] = "";

$CONF['admin_email'] = "support@somewhere.com";
$CONF['domain_in_mailbox'] = "YES";
$CONF['show_footer_text'] = "YES";
$CONF['footer_text'] = "something";
$CONF['footer_link'] = "something";

Securing the Postfixadmin 'admin' web interface

Assuming you want to control who can undertake administration on your newly installed server, you'll need to set a password for the admin user.

To do this, you will find it necessary to edit /var/www/postfixadmin-2.1.0/admin/.htaccess to fix the path for the .htpasswd file. It's also a good idea to change the admin password at this point using the htpasswd2 command.

From memory, I can't remember if the .htpasswd file exists or if it needs creating. (Mine is in postfixadmin-2.1.0/admin/). If it doesn't exist, you can create it using htpasswd2 -m /some/path/.htpasswd admin.

Some administrators may prefer the htpasswd file to live in e.g. /etc/apache2, and be called 'htpasswd' - this is fine - just make sure .htaccess is updated to reflect appropriately!

Sample .htaccess file

AuthUserFile /var/www/postfixadmin/admin/.htpasswd
AuthGroupFile /dev/null
AuthName "Postfix Admin"
AuthType Basic

require valid-user

This is quite a basic password configuration, see the Apache auth documentation for further information

Creating some test domains and users

We should now have the Postfix-PostgreSQL integration sorted, but the database doesn't have any configuration within it, therefore we need to login to postfixadmin, and create a test domain. Once the domain exists, we can add in a test user for that domain, and then see if everything works. Monitoring /var/log/mail.log will help!

The default username/password for postfixadmin is admin/admin (see above); you can add additional admin users if you wish.

Once you can successfully send mail to a user, you should find that in /var/mail/vmail there is a directory with the same name as the user's login.

Installing Courier

So far we've got to the position where we can receive mail, but now we need to be able to allow end users to retrieve it - via POP3 or IMAP.

This requires us installing courier, as follows :

apt-get install courier-pop courier-imap courier-authdaemon courier-imap-ssl courier-pop-ssl courier-authpostgresql

Note: The courier-authpostgresql package is in Ubuntu's Universe repository.

The courier-authpostgresql package will allow us to use the PostgreSQL database as our source of authentication for pop/imap users.

Configuring Courier

We need to edit /etc/courier/authpgsqlrc to insert our database settings, namely the following need changing :

PGSQL_HOST        localhost
PGSQL_PORT        5432
PGSQL_USERNAME    postfix
PGSQL_PASSWORD    something
PGSQL_DATABASE    postfix
PGSQL_USER_TABLE  mailbox
PGSQL_CRYPT_PWFIELD password
PGSQL_UID_FIELD   '1001'
PGSQL_GID_FIELD   '1001'
PGSQL_LOGIN_FIELD username
PGSQL_HOME_FIELD  '/var/mail/vmail'
PGSQL_NAME_FIELD  name
PGSQL_MAILDIR_FIELD maildir
PGSQL_QUOTA_FIELD quota

Next you'll need to edit /etc/courier/authdaemonrc, so Courier knows to use PostgreSQL.

authmodulelist="authpgsql"

Testing it all

Something like the below should work :

root@rvcu:~# tail -f /var/log/mail.log
root@rvcu:~# echo "test email" | nail -s "test email to me" dg@test.com
root@rvcu:~# Dec 28 14:57:27 localhost postfix/pickup[15230]: CBA2A127BBE: uid=0 from=
Dec 28 14:57:27 localhost postfix/cleanup[15710]: CBA2A127BBE: message-id=<20051228145727.CBA2A127BBE@localhost.localdomain>
Dec 28 14:57:27 localhost postfix/qmgr[15231]: CBA2A127BBE: from=, size=435, nrcpt=1 (queue active)
Dec 28 14:57:27 localhost postfix/virtual[15715]: CBA2A127BBE: to=, relay=virtual, delay=0, status=sent (delivered to maildir)
Dec 28 14:57:27 localhost postfix/qmgr[15231]: CBA2A127BBE: removed

root@rvcu:~# telnet localhost pop3
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
+OK Hello there.
user dg@test.com
+OK Password required.
pass test
+OK logged in.
Dec 28 14:58:38 localhost courierpop3login: Connection, ip=[::ffff:127.0.0.1]
Dec 28 14:58:49 localhost courierpop3login: LOGIN, user=dg@test.com, ip=[::ffff:127.0.0.1]
list
+OK POP3 clients that break here, they violate STD53.
1 493
.
quit
+OK Bye-bye.
Connection closed by foreign host.

Where to go from here

  1. Install/Setup Squirrelmail (see also here for a Squirrelmail Postfixadmin plugin
  2. Install/setup Horde
  3. Deploy

Screenshots?

Dave

I would love to see the screenshots to this, this is really interesting to me

Ade

Screenshots

See here for pictures.

Catch all mailbox

For a catch all mailbox see : here

Problem creating maildirs

Thanks for a great guide. I'm almost there and I think I have a reasonable understanding of how everything hangs together thank to this.

However, courier-imap doesn't seem to be able to create the mail directories by itself. Am I wrong in thinking that it should? If I'm not, any ideas as to why it is failing?

When I try to get email from the imap account samwise@hydrus.xx.xx, I see the following. Database back end is retrieving all the right values and authentication succeeds.

Jan 22 22:01:17 hydrus imapd-ssl: Connection, ip=[::ffff:xx.156.116.xx]
Jan 22 22:01:18 hydrus imapd-ssl: samwise@hydrus.xx.xx: chdir(/var/mail/vmail) failed!!
Jan 22 22:01:18 hydrus imapd-ssl: error: No such file or directory
Jan 22 22:01:18 hydrus imapd-ssl: LOGIN FAILED, method=PLAIN, ip=[::ffff:xx.156.116.xx]
Jan 22 22:01:18 hydrus imapd-ssl: authentication error: No such file or directory

hydrus ~# ls -la /var/mail/
total 8
drwxrwxr-x 2 root mail 4096 Jan 13 16:16 .
drwxr-xr-x 5 root root 4096 Jan 15 19:51 ..

However, when I create the directories manually (all gid mail and group writable), it goes beyond that, but mail client says "unable to open this mailbox"

Any hints are greatly appreciated

Problem creating maildirs

I think I figured out the problem by myself. Aparently postfix is the one creating all the directories using the UID and GID supplied in the database. So, when I changed the owner of /var/mail/vmail directory to 'postfix', everything was created (with vmail UID and GID). Now I'm going to try and change the owner of /var/mail/vmail to 'vmail' and see if it can still work. This is probably the preferred way.

Sam

Hi, Yes; the Maildir mail

Hi,

Yes; the Maildir mail boxes are created by Postfix, on delivery of mail. As long as /var/mail/vmail is writable by postfix, you'll be fine.

If the mailbox doesn't exist you may experience problems with the IMAP/POP3 server giving an error message when the end user attempts to login. For this reason, it's normally a good idea to send a "welcome" message upon creation of the mailbox.

Anti-Vir & Anit-Spam

Hi,
is there a how-to somewhere, how to add clam-av/f-prot and spamassassin?
Thanks a bunch,
Burkhard

you'd probably need to use

you'd probably need to use amavis for that.

David

postfixadmin

Great howto , thanks.!!!!

One thing, when i access postfixadmin, i get the error:

DEBUG INFORMATION:
Invalid query: ERROR: relation "admin" does not exist

Please check the documentation and website for more information.

Postfix Admin
Knowledge Base

There is absulotely nothing on the net about it and i cant figure it out.

Any ideas or 'pointer-in-the-right-directions' would be much appreciated to get this server up and functional

Shawn

SQL Schema loaded?

Hi,

I can only think that somehow your database isn't quite setup correctly. Is the postfixadmin web interface configured correctly to talk to your database?

I'll finally pull my finger out and install postfixadmin on another server soon, if I find any problems I'll then update this site.

David.

Invalid query: ERROR: relation "admin" does not exist

I, too, am getting this error. When I go to the http://[servername]/postfixadmin-2.1.0/setup.php page everything shows as being ok, but when I click on the "admin section" link, that is when it displays that error.

I am somewhat new to Linux, so any and all help would be appreciated.

Thank you,

Paul

When you ran cat

When you ran cat DATABASE_PGSQL.TXT | psql you did not have the database name set correctly to postfix - I just made that mistake and running the script again with the export for the db set correctly fixed it.

postfix 2.1 configuration

im running RHEL 4.0, i hav configured the basic setting in main.cf but im unable to send / recv mail. anyone can send me the confguration of postfix.

(mijildas@yahoo.com)

Newbie !! It doesnt work!!

Hi!
I did everything as u say and I have error using pstfixadmin
I dont know how use it. I get the firt page and I run the setup

Now when I go to url of my server I get this error:

Warning: pg_last_error(): No PostgreSQL link opened yet in /var/www/mailadmin/functions.inc.php on line 925

DEBUG INFORMATION:
Connect:

Please check the documentation and website for more information.

Postfix Admin
Knowledge Base

I get this when I try to go to admin section.
I run setup.php and Everything seems fine... you are ready to rock & roll!
But it is not true! Sad
Somebody can help me?
What can I do?

Check postgresql is running

Hi,

1) Check PostgreSQL is running; can you connect to it on localhost port 5432 (e.g. telnet localhost 5432).

2) Make sure Postfix admin is configured to use the right server (check config.inc.php)

3) Do you have php5-pgsql installed?

David.

That error it's because of

That error it's because of the Host-Based Authentication using pg_hba.conf.

You have to edit that file and replace "ident sameuser" in the METHOD tab with "md5" in the "host" and "local" type.
Then you have to restart the postgres service.

PostgreSQL SSL ....

I had an email today from someone trying to setup/install on Edgy Eft; to which my reply was :

Rob H wrote:
> Hi,
>
> I read your article about setting up Postfix with Postgres, and I've
> been trying to get it all to work. Everything seems fine up until the
> point where I create the mailbox in Postfixadmin. It does get created,
> the tables are updates in Postgres, but the actual DIR for the user
> created in /var/mail/vmail is *NOT* created. Up until I configure
> Postfix to use Postgres, I don't have any errors, then I start getting
> these two:
>

Hi Rob,

The mailboxes are created on demand by Postfix when it first receives an email for $user; therefore it's normally a good idea to send the 'welcome' email, so new users can connect to their mailbox ok.

I've not tried setting up Postfix admin on Edgy yet, but I wouldn't have thought there should be any real reasons why it won't work. I suspect your problems are somehow related to your attempted use of SSL with PostgreSQL. I've never setup PostgreSQL with SSL support before (or at least tried to use it!).

> postfix/trivial-rewrite[9370]: warning: connect to pgsql server
> localhost: SSL SYSCALL error: No such file or directory?
>
> postfix/trivial-rewrite[9370]: fatal:
> pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf(0,lock|fold_fix): table
> lookup problem
>
> There are a few others that come from postfix/smtpd and postfix/master,
> but they seem to point back to these postfix/trivial-rewrite events. The
> query does work manually from that .cf file, I have also tried to change
> the user to postfixadmin or another user that has all permissions
> granted. So, it doesn't seem to be a problem with rights. I read
> somewhere that it looks like Postfix is trying to connect via SSL and to
> configure Postgres to allow "hostssl" in "pg_hba.conf". I tried that,
> and it didn't help.

What does your pg_hba.conf file look like?
Try allowing local connections (127.0.0.1, localhost) through non-ssl?

>
> I'm using Ubuntu Edgy Server (32 bit), Postfix is 2.3.3 I believe, and
> Postgres is 8.1.4.
>
> Besides your article, I have read through this one:
> http://www.lxtreme.nl/index.pl/docs/linux/dovecot_postfix_pam
>
> Any thoughts?

See above; although I don't think I've added anything new!

is it working?

Hi, I have been following your procedures step by step for installing it in ubuntu edgy + postgres 8.1.Everything seems to be fine just I cannot make it work :))
I am at the point of having postfix admin up and running. What puzzles me is that I cannot seem to find a way to set up an email address as I am constantly given the message: Email not valid.
I must admit the corresponding host does not exists, meaning I have not registered with ICANN yet (just to be clear I tried to create a mailbox "renato" for the domain "mydomain.com" which has not been registered yet) I am not sure that is the reason. Moreover glancing your screenshots it seems like you should be able to have one admin being charge of more than one domain,in your screenshots the admin dg@clocksoft.com seems to be the admin of two domains. I have not found a way to select an existing admin for associating it to a domain. Last, but no least, the only link I have found for defining domains is the one you can find following the setup (when setup.php has not been removed), I could not find it anywhere else.
I do apreciate these could be postfixadmin support related questions, my problem is this is the first time I see postfix working and I am not able to understand whether some things do not work because of an incorrect setup procedure from my side.
Thank you for any time you can take to give me a hand
Sincerely
Renato Dall'Armi

ps actually there is one thing in your procedure I could not follow, when you said about editing /var/www/postfixadmin-2.1.0/admin/.htaccess to fix the path for the .htpasswd file:
I have not found any .htpasswd file nor I could find infos about the htpasswd2 command. It is there, it has no man associated and googleing it did not return any usefull info.

Some answers and rambling

Hi,
Thanks for the feedback.

When adding new domains, postfixadmin attempts to validate the domain - this normally just takes the form of a DNS lookup - so (as you say) because the domain isn't registered yet, it won't work. However, you can tell it (postfixadmin) to not check the validity of domains in it's config file (config.inc.php) :

$CONF['emailcheck_resolve_domain']='YES';

(Change to NO.... and problem #1 goes away :-) )

If you need to verify if postfixadmin/postfix/postgresql are all working and talking to one another; try the following :

  1. Verify Postfix can talk to PostgreSQL and get something valid; e.g. in my case, I can check to see if Postfix can find an alias specified in the database doing the following :

    $ postmap -q dof@codepoets.co.uk pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf
    david@codepoets.co.uk

    (So it works fine)

  2. If you tail -f /var/log/mail.log, and send an email, you should see Postfix handling it and delivering it to a mailbox

The .htaccess thing is as follows :

Within the 'admin' directory there should be a file called '.htaccess'; this is used to protect the contents of the directory from unauthorised people. By default it looks something like :

AuthUserFile /usr/local/www//admin/.htpasswd
AuthGroupFile /dev/null
AuthName "Postfix Admin"
AuthType Basic

require valid-user

It's a good idea to protect the 'admin' directory from users (as there is no other authentication/login used for the 'admin' section). Therefore you'll probably want to change the path to the .htpasswd file etc to make it work. In my case, I don't use it, as I already have an Apache Auth Check specified for a parent folder.

If you plan to use this .htaccess file, then you'll need to create a file for the AuthUserFile directive. It can be called whatever you want. To create use :

htpasswd2 -m /path/to/my/file a_user_name

(On some distros 'htpasswd2' may just be 'htpasswd')

Hope that helps
David.

Zuccante?

Renato,

are you the one who was sitting by me at Zuccante when Pecorari sent you off the room that first day?

Walter

pecorari

Uhmm... stiamo andando molto indietro nel tempo....Credio di essere quel renato, solo che la persona in questione non era Pecorari ma un altro "figuro" chiamato Torroni e in questo caso tu dovresti esserere Walter Mac. di Padova......

se ripassi, puoi scrivermim a r d alla rmi chiocciola mail di google punto com

getting there

Hallo David, thanks for your help.
I am getting there, with just two little things:

1st I am not asked any username/password for accessing http://mysite/postfixadmin/admin, it is for everybody to edit.

following your procedure I have changed .htaccess which looks now like:

AuthUserFile /var/www/postfixadmin-2.1.0/admin/.htpasswd
AuthGroupFile /dev/null
AuthName "Postfix Admin"
AuthType Basic

require valid-user

I have also modified the admin password by using: sudo htpasswd -c .htpasswd admin in the postfix/admin directory.
Permissions are set like: (for all files in the admin directory I report just 5 for brevity)

-rw-r----- 1 www-data www-data 2747 2005-01-07 00:00 edit-alias.php
-rw-r----- 1 www-data www-data 2966 2007-01-24 10:51 edit-domain.php
-rw-r----- 1 www-data www-data 4009 2007-01-24 10:51 edit-mailbox.php
-rw-r----- 1 www-data www-data 168 2007-01-25 16:34 .htaccess
-rw-r----- 1 www-data www-data 20 2007-01-25 16:30 .htpasswd

2nd there is no way I found to associate a domain to an existing admin, no by editing a domain, not by editing the admin, how do you normally do that?

perhaps some answers

Hi,

1) Apache probably has 'AllowOverride None' in it's config; you'll need to change this (the simplest is 'AllowOverride ALL') to allow .htaccess style files to work.

2) When you create/edit an admin you can select a list of domains they are admin of. It doesn't look like you can select a list of admins for a domain when creating the domain.

Glad to hear things are working...

thanks
David.

postfix on edgy

I have been trying to install postfix/postfixadmin onto ubuntu edgy 6.10 X86_64 I have been experiencing the same error as one of the previous posters "SSL SYSCALL error: No such file or directory?" that is not due to trying to use SSL, but, as it turns, from the lack of SSL support. Once SSL support has been granted to postgres that error goes away. I am now fighting with a virtual_alias_maps map lookup problem for root@broker-group.es, but it could be these errors have to do with some access problems due to lack of SSL support up to this morning

Fix for "SSL SYSCALL error: No such file or directory?"

You can use the prxoymap instead of fiddling around the postfix's chroot settings or postgresql. When you use Proxymap you hit two birds with one stone, eliminating the chroot problem and save some resource.

From postfix doc:
"To overcome chroot restrictions. For example, a chrooted SMTP server needs access to the system passwd file in order to reject mail for non-existent local addresses, but it is not practical to maintain a copy of the passwd file in the chroot jail."

"To consolidate the number of open lookup tables by sharing one open table among multiple processes. For example, making mysql connections from every Postfix daemon process results in "too many connections" errors."

Modify your main.cf like this
virtual_alias_maps = proxy:pgsql:/etc/postfix/virtual_alias.cf

This way all of the chrooted daemons will connect to PostgreSQL through the non chrooted proxymap daemon and it will work perfectly. As a "side effect" you'll have less concurrent connection to PostgreSQL.

the SSL problem (localhost:

the SSL problem (localhost: SSL SYSCALL error: No such file or directory?) is not due to SSL, but instead to improper setting of the postfix configuration file main.cf. postfix does not want to be run chrooted so, **every** service listed must be **explicitally** told not to run chrooted. As it is by default in edgy, all services are chrooted and that is the problem.

I am facing a problem with courier instead. while trying to login to a test account I get

Feb 21 19:30:13 server authdaemond: Connection to server 'localhost.' userid 'postfix.' database 'postfix' failed.
Feb 21 19:30:13 server authdaemond: could not translate host name "localhost." to address: Name or service not known.
Feb 21 19:30:13 server courierpop3login: LOGIN FAILED, user=massimo@eudealers.com, ip=[::ffff:127.0.0.1]
Feb 21 19:30:13 server courierpop3login: authentication error: Input/output error

now I can psql -d postfix -h localhost -U postfix with no problem so the problem does not seem to be at the database level...... any clue?
tx
Renato

authdaemond - weird

I presume '127.0.0.1 localhost' exists in /etc/hosts? Does using 'courierauthtest' help?

David.

authdaemond - weird

hi, not there yet, but close. That problem was due to the facts there was a traling tab in the various *map.cf, due to me cut and paste from your web page :)) now thad still doesn't cut it with ubuntu edgy, because once that is solved.. you just bump into the new problem. In edgy there is what I beleive it s bug in the authdeamon, so that even if you import the new package (whose name is different in edgy from dapper) for postgres support, the package does not later the configuration file /etc/authdeamonrc. You have to do it manually and add one line:

authmodulelist="authpgsql"

as usually, solutions drive you into new problems,now if I try to email to a test account, the email goes trough, but if I (as in your tutorial) telnet into the localhost pop3 and I try to retrieve my mail,I get an err:
-ERR chdir Maildir failed

or in the mail log:
server courierpop3login: chdir Maildir: No such file or directory

I went to verify, the maildir seems to be actually there; for the account
massimo@eudealers.com I have, in /var/mail

drwxr-sr-x 4 1001 mail 4096 2007-02-21 21:36 vmail

in /var/mail/vmail

drwx--S--- 5 1001 mail 4096 2007-02-21 21:36 antonio@eudealers.com
drwx--S--- 5 1001 mail 4096 2007-02-21 16:58 massimo@eudealers.com

in /var/mail/vmail/massimo@eudealers.com
drwx--S--- 2 1001 mail 4096 2007-02-21 16:58 cur
drwx--S--- 2 1001 mail 4096 2007-02-21 21:21 new
drwx--S--- 2 1001 mail 4096 2007-02-21 21:21 tmp

in /var/mail/vmail/new (and finally)
-rw------- 1 1001 mail 560 2007-02-21 16:58 1172073501.V813I6b5e7M898680.server
-rw------- 1 1001 mail 560 2007-02-21 21:21 1172089319.V813I6b5eaM847753.server

where the second is the test message I just sent so I am not sure what Maildir the system cannot chdir to or for what permission problem

Sorry for the verbose note, unfortunately I seem to be the first one that, on edgy got this far (or at least that writes about it), everybody else I read about seem to have stopped at the SSL problem stage; for once it it nice paving the way for the others... well, the new ubuntu is about to be out, so maybe this is a waste of effort....

chdir etc

Normally the "cannot chdir()" thing occurs if the user's mailbox doesn't (yet) exist; which is why it's a good idea to always send the test message when creating a new account.

Clearly in your case this can't be the problem, so I suspect that perhaps you need to check the PGSQL_HOME_FIELD in /etc/courier/authpgsqlrc

Sorry about the issue with tabs etc :)

problem with courier

Hi, I wanted to post an update on this issue, because it can save long sleepless night to numerous people.
The problem above was due to ubuntu (edgy and feisty) presenting the setting "PGSQL_MAILDIR_FIELD" and "PGSQL_NAME_FIELD" with a trailing blank on the line, make sure the line containing those two parameters does not start with a blank, otherwise you would get the error above
Renato

I cannot login to postfixadmin after I already install

Please help me to solve the problem.

what about IMAP?

Hi, I have been following the procedure (and done a lot of debugging because edgy seems to be not as "mature as dapper) and I have postfix/postgres/postfixadmin up and running, I can access my email using pop3.....not so sure about IMAP.
If I set kmail to access my server using IMAP it just hung in there with "checking account for new email". is there anything I have to do to enable IMAP besides following the procedure above?
thanks
Renato

What about IMAP ?

i used this guide and a couple of others to install postfix, postfixadmin, courier imap, imaps, pop3d and pop3d on a mandriva 2007 distro. on another system i have postgres 8.1 running (also on a mandriva 2007 distro) and i must say that once i got the maildir permissions issue resolved (discovered postfix is running as 'nobody', at least that's the way the mail dirs are being created) everything came up and worked 100%...both imap and pop3. have not tried the ssl stuff yet.

nice job.

Squirrelmail plugin

The following may be of use :


Updated Squirrelmail plugin for Postfixadmin

Problem postfix + postgre

Hi,

I've got some problms with postfix and postgre.

My first problem was the same as described By renato (not verified) at 2007-02-22 09:18

So postfix admin said it has send a test email to new user. In fact either by postfixadmin either by a test with email client, the /var/mail/vmail/the_new_user@its_domain is never created...

So I create it by hands and i do a chow 700 (how to set drwx--S--- permission ?) and I create the subdirectories...

Now I can connect by telnet.

But email system still not working.

with a tail /var/log/mail.err I can see that :
Apr 7 14:53:28 courriel1 postfix/trivial-rewrite[2596]: fatal: pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf(0,lock|fold_fix): table lookup problem

So I will be very happy if someone can help me to fix that.

Thanks a lot

STef

re problem...

1) Check the permissions of /var/mail/vmail - mine is owned by mail:mail.

2) Postfix should create the mail directories if they do not exist. If it doesn't (and it's not a permissions problem), it's almost certainly a configuration issue. I presume there was something in /var/log/mail.log saying the mail had been delivered?

3) You can use 'postmap -q' to query the configuration, e.g.

[EDIT - fixed arguments order! 2007/04/10]
postmap -q someone@somewhere.com pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf
[/EDIT]

(Assuming someone@somewhere.com is an alias entry).

This will do a lookup via PostgreSQL for the appropriate alias, using the settings in virtual_alias_maps.cf.

Perhaps you have a typo in the virtual_alias_maps.cf file?

re problem : debugging

Oki, it seems I've got a configuration problem.

postmap -q pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf alias_name@domain.eu
postmap: fatal: open database alias_name@domain.eu.db: No such file or directory

I've checked the pgsql/* files, there are the same as thoses in this site (with my parameters).
I can also use the postgres database without problem with this command:
psgl -U postfixadmin postfix

a tail /var/log/mail.log says the same :
Apr 10 20:28:20 courriel1 postfix/postmap[5208]: fatal: open database alias_name@domain.eu.db: No such file or directory

The alias I've created was done with postfixadmin and points to a virtual domain managed by postfix (and also configured with postfixadmin).

So David is right : I've got a serious problem with my postfix configuration

There's also a reccuring message who comes everytime in /var/log/mail.log (even when I don't do anything). I put a little copy/paste here, maybe it could help.

root@courriel1:/etc/postfix# tail /var/log/mail.log
Apr 10 20:29:04 courriel1 postfix/smtpd[4539]: send attr request = resolve
Apr 10 20:29:04 courriel1 postfix/smtpd[4539]: send attr sender =
Apr 10 20:29:04 courriel1 postfix/smtpd[4539]: send attr address = stef@main_virtual_domain.com
Apr 10 20:29:04 courriel1 postfix/smtpd[4539]: private/rewrite socket: wanted attribute: flags
Apr 10 20:29:04 courriel1 postfix/smtpd[4697]: rewrite stream disconnect
Apr 10 20:29:04 courriel1 postfix/smtpd[4697]: connect to subsystem private/rewrite
Apr 10 20:29:04 courriel1 postfix/smtpd[4697]: send attr request = resolve
Apr 10 20:29:04 courriel1 postfix/smtpd[4697]: send attr sender =
Apr 10 20:29:04 courriel1 postfix/smtpd[4697]: send attr address = stef@main_virtual_domain.com
Apr 10 20:29:04 courriel1 postfix/smtpd[4697]: private/rewrite socket: wanted attribute: flags

Another thing is I don't realy trust postfixadmin. I would like to create some entries by myself but I don't know how to put an encrypted password in the password field of postgresql.

I would also thank for this debian/ubuntu usefulf website and the help reveived.

STef

Ick; typo on my behalf - arguments in wrong order for postmap...

Hi,

It should be something like :

postmap -q someone@somewhere.com pgsql:/etc/postfix/pgsql/.....

Not the other way around; sorry!

David.

corrected command works but system still not working

Many thanks,

So the following command is working :

root@courriel1:/etc/postfix# postmap -q alias_name@one_domain.eu pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf

It returns :
real_name@one_domain.eu

There's nothing particular when I do /var/log/mail.log except a new instance of the message I've mentionned before.
Something I didn't write is that my server has 2 ip adresses : One public (eth0) (for receiving and sending emails) and one private (eth1) (to communicate with the postfixadmin server). Maybe it is mandatory to say postfix what to do with each intefaces.

I've tried one more time to send emails to accounts created with postfixadmin using my account provided by my adsl provider
It still not working : mailboxes aren't created in /var/mail/vmail (i've do a chmod mail:mail on /var/mail/vmail as suggested by David).

I did the following checks :

1) An NS lookup on the MX record of my destination domain on http://www.zoneedit.com the answer is correct so I don't have a DNS problem

2) when doing a tail /var/log/mail.err I see some identical lines :
Apr 10 22:27:04 courriel1 postfix/trivial-rewrite[6322]: fatal: pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf(0,lock|fold_fix): table lookup problem
it's very strange becoz the (new) test command provided by David worked fine

It seems also I've got a problem when trying (using both ftp method and email client) to check emails :
authentification failed (login name = complete_email_adress ; pass = pass filled in the postfixadmin interface)

Maybe is there a problem with the hash of the password ?

thanks for help

a password issue wouldn't stop you receiving mail

Hi,

Receiving mail would not be affected by an incorrect password; it should still get delivered to the right directory - it's just retrieval by pop3/imap that would be.

I think there's a problem with your virtual_alias_maps.cf file - can you check the PostgreSQL log files (/var/log/postgresql I think), and if there isn't anything interesting in them, turn up PostgreSQL's debugging so it logs all queries (see /etc/postgresql/postgresql.conf)

cannot debug postfix

So,

Thanks to David I understand the source of my problem.

So I did the following :
A back-up of the /etc/postfix/pgsql directory
/etc/init.d/postfix stop
rm -rf /etc/postfix
rm /var/log/mail.log
rm /var/log/mail.err
rm /var/log/mail.info
rm /var/log/mail.warn
apt-get --purge remove postfix postfix-pgsql
apt-get install postfix postfix-pgsql

The version of postfix is 2.3.3-1 on a Ubuntu 2.6.17-11.35-server

When it asked me what kind of configuration I want, I've answered 'internet site'

In main.cf, I've commented the following lines :
####alias_maps = hash:/etc/aliases
####alias_database = hash:/etc/aliases
####mailbox_size_limit = 0

Then I test the relaying (telnet localhost 25) and it works (I've send a email to an existing email account of mine and received it)

I noticed that I do not receive anything more in my /var/log/mail.* and i've put
smtp inet n - - - - smtpd -v
in master.cf

I've activated some logging into postgresql (and restarted it) so as suggested by David

After that, I've restored the /etc/postfix/pgsql directory and appended the config part for the virtual domains in the main.cf and restarted postfix

I can do a postmap -q .... pgsql:/etc/postfix/pgsql/virtual_alias_maps.cf and it works

But relaying don't work anymore :
telnet localhost 25 answers and if I type 'quit' it disconnects normally. When, after connection, I put a rcpt to: it don't answer anything and CTRL-C don't stop the connexion. To end properly the connexion I've to do a /etc/init.d/postfix stop

When I do a tail /var/log/postgresql/postgresql-8.1-main.log I don't see anything interesting :
LOG: autovacuum: processing database "postfix"
LOG: autovacuum: processing database "postgres"
...

And I still not receiving any more log in my /var/log/mail.* files :s

So there's something wrong with postfix but I cannot find what...

postfix problem solved

So,

I've solved the problem and I'm writing the solution who worked for me (+ some additionals questions), maybe it could be usefull for other people.

In fact, I've founded the solution here :
http://ubuntuforums.org/showthread.php?t=332269&highlight=postfix+%2B+postgres

a) I enabled postgres ssl connections by editing pg_hba.conf and adding a line
hostssl all all 192.168.1.0/24 md5
where 192.168.1.0/24 is the ip range I wanted to enable

b) I edited /etc/postfix/master.cf and disabled all chrooted services, as it comes by default all services seem to run chrooted

this should let the SSL error go...but that was not enough
then you have to go to edit the file /etc/authdeamonrc
and add a line
authmodulelist="authpgsql"

At the beginning, I've tried to deactivate the chroot for local, pipe, spawn, virtual and proxymap as suggested in the man (man 5 master).
But It didn't solved the problem at all. Then after, I've desactivated the chroot everywhere and relaying was running well again.

(1) I don't know anything about the consequences of that so my first question is 'Do I have put a security hole on my server ?'

(2) My second question is : Is it a way to make it running with the defaults 'chroot' and if not, why ?

I have also solved the problem of the user's directory who were not automaticaly created :
a tail /var/log/syslog teached me it was a right problem. So I've just did a chown 1001 /var/mail and chown 1001 /var/mail/vmail

It seems that the user who owns the /var/mail and /var/mail/vmail doesn't really matter (to make it work, for security, it does matter). The important thing is that the id's and uid's mentioned in /etc/postfix/main.cf must match the id and uid who owns /var/mail and /var/mail/vmail

So that's it. I will go further in my configuration next week-end.

STef

password authentication failed

I was following the steps in "Creating the PostgreSQL database structure", after executing "cat DATABASE_PGSQL.TXT | psql", I get an error of

psql: FATAL: password authentication failed for user "postgres"

Check pg_hba.conf

When you are logged in as the user 'postgres' under Linux, the default behaviour of PostgreSQL is to allow that user to execute any query without a password. If you can't do this (which appears to be the case) then you need to look at pg_hba.conf and edit it appropriately.

pg_hba.conf

What should the configuration be in pg_hba.conf?

Currently, this is what I have:

local all all ident sameuser
host all all 127.0.0.1/32 md5

that looks fine...

That looks fine; so presumably you can then :

  • su - (become root from $non-root-user
  • su - postgres (become postgres from root)
  • <run query>

(i.e. your pg_bha.conf says you can become the postgresql 'postgres' user, without a password, only if you're connecting from the linux system account 'postgres').

postfix SQL problem.

Hey,

I've got a postfix configuration with a MySQL database.

I've got the folowing error in my mail.log :

May 26 18:02:16 VirtualUbuntu postfix/cleanup[10399]: warning: BD6A9D6300: virtual_alias_maps map lookup problem for postmaster@example.com

When I run this command: root@VirtualUbuntu:/etc/postfix/sql# postmap -q "postmaster@example.com" mysql:/etc/postfix/sql/virtual_alias_maps.cf

I get the correct result: bamm.bamm@example.com

So the permissions on the tables for postfix are correct. But why do i get this error.

A part of my main.cf looks like this:

myhostname = mail.example.com
mydestination = $mydomain, $myhostname, localhost.localdomain, localhost
virtual_mailbox_domains = mysql:/etc/postfix/sql/virtual_mailbox_domains.cf
virtual_uid_maps = mysql:/etc/postfix/sql/virtual_uid_maps.cf
virtual_gid_maps = mysql:/etc/postfix/sql/virtual_gid_maps.cf
virtual_mailbox_maps = mysql:/etc/postfix/sql/virtual_mailbox_recipients.cf
virtual_alias_maps = mysql:/etc/postfix/sql/virtual_alias_maps.cf
relayhost =
mynetworks_style = class
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
local_transport = maildrop
maildrop_destination_recipients_limit = 1

Can anyone help me?

Thnx!

Greetings,

David

(0,lock|fold_fix): table lookup problem

Hi,
i got here from googling on my problem, here goes:

Jun 27 22:47:18 mail postfix/trivial-rewrite[37514]: warning: mysql query failed: MySQL server has gone away
Jun 27 22:47:18 mail postfix/trivial-rewrite[37514]: fatal: mysql:/usr/local/etc/postfix/mysql/virtual_alias_maps.cf(0,lock|fold_fix): table lookup problem

(this is from maillog).
I have postfix+mysql virtual users and aparently all works, ie: I can send/recieve emails, accounts are created from postfix admin etc. But i keel getting those lines in maillog, whats the problem, i suspect the mysql server isnt playing nice, BUT what is the problem ? :(

incorrect table name?

- is the table name correct?
- is the database name correct?
- does mysql listen on e.g. tcp/ip or is it only listening on a socket?

(random guesses, hope it helps!)

David.

Ubuntu Fix for this tutorial.

Hi there folks,

This How-To is very good, thanks a lot!
Well, I was having trouble in default Ubuntu Dapper (Server LTS) install, somehow when I was trying to add users in virtual domains I was getting this log:

Mar 4 07:56:10 alucard postfix/smtpd[4239]: warning: premature end-of-input on private/rewrite socket while reading input attribute name
Mar 4 07:56:10 alucard postfix/smtpd[4239]: warning: problem talking to service rewrite: Success
Mar 4 07:56:10 alucard postfix/master[3700]: warning: process /usr/lib/postfix/trivial-rewrite pid 4262 exit status 1
Mar 4 07:56:10 alucard postfix/master[3700]: warning: /usr/lib/postfix/trivial-rewrite: bad command startup -- throttling

Some googling before, I found that Ubuntu has SSL broken in PostgreSQL by default: http://lists.tummy.com/pipermail/vpostmaster/2006-August/000406.html

The fix for this was changing /etc/postgresql//main/postgresql.conf

where says: ssl=true
change to: ssl=false

Restarted service postgresql and I could at least add an user:
Mar 4 07:57:10 alucard postfix/smtpd[4239]: B9528B728D: client=localhost[127.0.0.1]
Mar 4 07:57:10 alucard postfix/cleanup[4311]: B9528B728D: message-id=<20080304105710.B9528B728D@alucard>
Mar 4 07:57:10 alucard postfix/qmgr[3705]: B9528B728D: from=, size=467, nrcpt=1 (queue active)
Mar 4 07:57:10 alucard postfix/smtpd[4239]: disconnect from localhost[127.0.0.1]
Mar 4 07:57:10 alucard postfix/virtual[4313]: B9528B728D: to=, relay=virtual, delay=0, status=sent (delivered to maildir)
Mar 4 07:57:10 alucard postfix/qmgr[3705]: B9528B728D: removed

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.

More information about formatting options

CAPTCHA
This question is used to make sure you are a human visitor and to prevent spam submissions.
11 + 2 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.