# Virtual Mail according to howto,does not work

## boudewijn

Hi

I've followed this link:

http://www.gentoo.org/doc/en/virt-mail-howto.xml

This because at the moment my single-domain setup is down , and I decided to upgrade it for virtual use.

At the moment, it will be used for 14 domains. (the single-domain setup did that quite well, but boudewijn@foo.com was the same box as boudewijn@foo-bar.com).

I picked two of them to test with:

boudewijnector.nl (yeah that's me)

gentoo-forum.nl 

Step 2:

 postfix (I have read the O reilly book about postfix by the way, so I know fairly what I'm doing).

My config:

```

queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/lib/postfix

mail_owner = postfix

unknown_local_recipient_reject_code = 550

debug_peer_level = 2

debugger_command =

         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin

         xxgdb $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail

newaliases_path = /usr/bin/newaliases

mailq_path = /usr/bin/mailq

setgid_group = postdrop

html_directory = /usr/share/doc/postfix-2.2.5/html

manpage_directory = /usr/share/man

sample_directory = /etc/postfix

readme_directory = /usr/share/doc/postfix-2.2.5/readme

home_mailbox = .maildir/

local_destination_concurrency_limit = 2

default_destination_concurrency_limit = 10

smtpd_sasl_auth_enable = yes

smtpd_sasl2_auth_enable = yes

smtpd_sasl_security_options = noanonymous

broken_sasl_auth_clients = yes

smtpd_sasl_local_domain =

smtp_tls_note_starttls_offer = yes

smtpd_use_tls = yes

smtpd_tls_key_file = /etc/postfix/newreq.pem

smtpd_tls_cert_file = /etc/postfix/newcert.pem

smtpd_tls_CAfile = /etc/postfix/cacert.pem

smtpd_tls_loglevel = 3

smtpd_tls_received_header = yes

smtpd_tls_session_cache_timeout = 3600s

tls_random_source = dev:/dev/urandom

smtpd_recipient_restrictions =

        permit_sasl_authenticated,

        permit_mynetworks,

        reject_unauth_destination

alias_maps = mysql:/etc/postfix/mysql-aliases.cf

relocated_maps = mysql:/etc/postfix/mysql-relocated.cf

local_transport = local

local_recipient_maps = $alias_maps $virtual_mailbox_maps unix:passwd.byname

virtual_transport = virtual

virtual_mailbox_domains =boudewijnector.nl, gentoo-forum.nl

virtual_minimum_uid = 1000

virtual_gid_maps = static:1003

virtual_mailbox_maps = mysql:/etc/postfix/mysql-virtual-maps.cf

virtual_alias_maps = mysql:/etc/postfix/mysql-virtual.cf

        virtual_uid_maps = static:1003

                        virtual_mailbox_base = /

```

The file looked like this after the step, and it worked well (tested using mutt, by sending from root a mail to boudewijn@localhost) :

```

queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/lib/postfix

mail_owner = postfix

unknown_local_recipient_reject_code = 550

debug_peer_level = 2

debugger_command =

         PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin

         xxgdb $daemon_directory/$process_name $process_id & sleep 5

sendmail_path = /usr/sbin/sendmail

newaliases_path = /usr/bin/newaliases

mailq_path = /usr/bin/mailq

setgid_group = postdrop

html_directory = /usr/share/doc/postfix-2.2.5/html

manpage_directory = /usr/share/man

sample_directory = /etc/postfix

readme_directory = /usr/share/doc/postfix-2.2.5/readme

home_mailbox = .maildir/

local_destination_concurrency_limit = 2

default_destination_concurrency_limit = 10

```

Changed master.cf according to the howto, then ran newaliases and restarted postfix.

Everything fine.

Step 3

Things stopped to work here. I got an error. Login failed , according to thunderbird .

I decided to go on, because I think it's due to the way of authentication which will be changed later on.

Step 4+5

Step 4+5 are imo irrelevant (please tell me if those are not), because the problem isn't SSL related and I haven't used SSL yet (just plain IMAP). I have followed the instructions in these steps though (just like in 6).

Step 6

The telnet test did work at the end of step 6. Mysteriously it doesn't now (when posting this post), but that may be due to modifications made later, I guess.

Step 7

I presume something went wrong here.

First I've added a user:

```

mysql> select * from users;

+----+-----------------------------+-------+-----------+------+------+-------------+--------------------------------------------------+-------+---------+

| id | email                       | clear | name      | uid  | gid  | homedir     | maildir                                          | quota | postfix |

+----+-----------------------------+-------+-----------+------+------+-------------+--------------------------------------------------+-------+---------+

|  3 | boudewijn@boudewijnector.nl | test  | Boudewijn | 1003 | 1003 | /home/vmail | /home/vmail/boudewijnector.nl/boudewijn/.maildir |       | y       |

+----+-----------------------------+-------+-----------+------+------+-------------+--------------------------------------------------+-------+---------+

1 row in set (0.00 sec)

```

Had to change the uid and gid later on, because the vmail user did NOT exists.

This seems to me like a bug in the howto (just like you're told to connect to DB mysql instead of mailsql).

Added some aliases (just for testing):

```

mysql> select * from alias;

+----+------------+------------------------------+

| id | alias      | destination                  |

+----+------------+------------------------------+

|  1 | root       | root@boudewijnector.nl       |

|  2 | postmaster | postmaster@boudewijnector.nl |

+----+------------+------------------------------+

```

Virtual is empty, just like relocated.

```

mysql> select * from transport;

+----+-------------------+-------------+

| id | domain            | destination |

+----+-------------------+-------------+

|  1 | boudewijnector.nl | local:      |

|  2 | gentoo-forum.nl   | virtual:    |

+----+-------------------+-------------+

```

I wonder whether this shouldn't be virtual? 

Just tried using virtual instead of local for boudewijnector.nl ,and it didn't work either.

Step 8:

Dropped it. Apache and phpmyadmin ARE already running great.

Step 9:

Done. The 1003 from the users table is derived from this step.

Check:

```

dionysos postfix # grep vmail /etc/passwd ; grep vmail /etc/group

vmail:x:1003:100::/home/vmail:/bin/false

vmail:x:1003:

```

Seems to be like 1003.  (confirmed by:  uid=`cat /etc/passwd | grep vmail | cut -f 3 -d :` ; echo $uid  ).

Step 10

Ok, I've changed main.cf (see top of the post).

My /etc/courier/authlib/authmysqlrc :

```

MYSQL_SERVER            localhost

MYSQL_USERNAME          mailsql

MYSQL_PASSWORD          *** (removed by /me)

MYSQL_DATABASE          mailsql

MYSQL_USER_TABLE        users

MYSQL_CLEAR_PWFIELD     clear

MYSQL_UID_FIELD         uid

MYSQL_GID_FIELD         gid

MYSQL_LOGIN_FIELD       email

MYSQL_HOME_FIELD        homedir

MYSQL_NAME_FIELD        name

MYSQL_MAILDIR_FIELD     maildir

```

Other file:

```

dionysos postfix # grep -v '#' /etc/courier/authlib/authdaemonrc | grep [a-z]

authmodulelist="authmysql authpam"

authmodulelistorig="authuserdb authpam authshadow authldap authmysql authcustom authpipe"

daemons=5

authdaemonvar=/var/lib/courier/authdaemon

```

Afterwards, I did the chmod and chgrp , and restarted+reloaded postfix.

Now it still doesn't work.

I try (using mozilla thunderbird at my workstation) :

Host: 192.168.1.4 (is correct, and I know for sure there are no DNS-related problems).

Username : boudewijn@boudewijnector.nl

Password: test

Protocol: IMAP 

Thunderbird says:

Login to server 192.168.1.4 failed.

Well, I don't know what's wrong here.

Followed this official (?) howto, and it still doesn't work. It's too complex for me to just try around messing with variables.

Please help!

----------

## langthang

try something like

```
telnet 192.168.1.4 143

Trying 192.168.1.4...

Connected to 192.168.1.4.

Escape character is '^]'.

* OK <server banner>

a01 login boudewijn@boudewijnector.nl test ### from your username and password above

a01 OK LOGIN Ok.

a02 logout

* BYE LOGOUT received

a02 OK Completed

Connection closed by foreign host.

```

if there is errors, post them. also look in /var/log/mail.log or something simliar for clue.

----------

## boudewijn

tried from the server itself :

```

dionysos postfix # telnet localhost 143

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc.  See COPYING for distribution information.

login boudewijn@boudewijnector.nl test

login NO Error in IMAP command received by server.

```

in /var/log/messages (checked it, but forgot to mention it in start-post   :Embarassed:   ):

```

Feb  7 01:52:11 dionysos imapd: Connection, ip=[127.0.0.1]

Feb  7 01:52:55 dionysos postfix/cleanup[17505]: fatal: open dictionary: expecting "type:name" form instead of "virtual_uid_maps"

Feb  7 01:52:56 dionysos postfix/master[16959]: warning: process /usr/lib/postfix/cleanup pid 17505 exit status 1

Feb  7 01:52:56 dionysos postfix/master[16959]: warning: /usr/lib/postfix/cleanup: bad command startup -- throttling

Feb  7 01:52:59 dionysos imapd: Disconnected, ip=[127.0.0.1], time=48

Feb  7 01:53:01 dionysos cron[17507]: (stats) CMD (/home/stats/genstats)

```

----------

## langthang

you have to type in

```
A01 login boudewijn@boudewijnector.nl test
```

or you will get

```
login NO Error in IMAP command received by server.
```

the error

```
Feb  7 01:52:55 dionysos postfix/cleanup[17505]: fatal: open dictionary: expecting "type:name" form instead of "virtual_uid_maps"
```

causes by the leading white space(s)

```
        virtual_uid_maps = static:1003

                        virtual_mailbox_base = / 
```

change to:

```

virtual_uid_maps = static:1003

virtual_mailbox_base = / 
```

----------

## boudewijn

Gosh!

I've edited the config:

```

dionysos log # /etc/init.d/postfix restart

 * Stopping postfix ...                                                               [ !! ]

dionysos log # /etc/init.d/postfix start

 * WARNING:  "postfix" has already been started.

dionysos log # /etc/init.d/postfix zap

 * Manually resetting postfix to stopped state.

dionysos log # /etc/init.d/postfix start

 * Starting postfix ...                                                               [ !! ]

```

/var/log/messages says:

Feb  7 02:10:26 dionysos postfix/postfix-script: fatal: the Postfix mail system is already running

How to fix this? I've zapped it, but postfix thinks it's still running.

----------

## boudewijn

well I'm sleepy (I guess... it's after 2 am over here):

```

dionysos log # ps aux | grep post

root     16959  0.0  0.2  29012  2244 ?        Ss   00:45   0:00 /usr/lib/postfix/master

postfix  16965  0.0  0.2  29220  2400 ?        S    00:45   0:00 qmgr -l -t fifo -u

postfix  17538  0.0  0.2  29072  2272 ?        S    01:56   0:00 pickup -l -t fifo -u

postfix  17886  0.0  0.2  29216  2524 ?        S    02:09   0:00 trivial-rewrite -n rewrite -t unix -u

postfix  17894  0.0  0.2  29292  2572 ?        S    02:09   0:00 local -t unix

postfix  17898  0.0  0.2  29288  2568 ?        S    02:09   0:00 local -t unix

postfix  17904  0.0  0.2  29092  2280 ?        S    02:09   0:00 bounce -z -t unix -u

postfix  17907  0.0  0.2  29232  2496 ?        S    02:09   0:00 virtual -t unix

postfix  17915  0.0  0.2  29096  2284 ?        S    02:09   0:00 bounce -z -t unix -u

postfix  17920  0.0  0.2  29092  2280 ?        S    02:09   0:00 bounce -z -t unix -u

postfix  17922  0.0  0.2  29272  2544 ?        S    02:09   0:00 cleanup -z -t unix -u

postfix  17924  0.0  0.2  29276  2552 ?        S    02:09   0:00 cleanup -z -t unix -u

postfix  17930  0.0  0.2  29276  2552 ?        S    02:09   0:00 cleanup -z -t unix -u

postfix  17931  0.0  0.2  29096  2284 ?        S    02:09   0:00 bounce -z -t unix -u

dionysos log #

                                                               
```

I'll just kill them, and continue the testing.

----------

## boudewijn

ok the telnet part works:

```

dionysos log # telnet localhost 143

Trying 127.0.0.1...

Connected to localhost.

Escape character is '^]'.

* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE ACL ACL2=UNION STARTTLS] Courier-IMAP ready. Copyright 1998-2005 Double Precision, Inc.  See COPYING for distribution information.

A01 login boudewijn@boudewijnector.nl test

A01 OK LOGIN Ok.

A02 logout

* BYE Courier-IMAP server shutting down

A02 OK LOGOUT completed

Connection closed by foreign host.

dionysos log #

 
```

I'll try thunderbird now.

----------

## boudewijn

Thanks it works now!

Just checked the postfix-book ( http://www.oreilly.com/catalog/postfix/index.html ) and it doesn't say indentation is bad.

But I guess I miscopied it from the howto (maybe it would be smart to tell it's not 1 line).

Thanks man!

SOLVED

----------

## boudewijn

one tiny last problem:

I was just trying to send some mail , and thunderbird tells me:

```

The current command did not succeed. The mail server responded: [TRYCREATE]. 

Must create mailbox before append.

```

I've just moved my /home/boudewijn/.maildir to /home/vmail/boudewijnector.nl/boudewijn/.maildir.

Chowned it al to vmail , and I've recovered my ca. 1600 emails.

But I can't send?

Jus tried googling, but all i found were some RFCs etc.

Got a solution\tip?

----------

## langthang

check for a ".Sent" folder in "/home/vmail/boudewijnector.nl/boudewijn/.maildir" . create it with `maildirmake -f /home/vmail/boudewijnector.nl/boudewijn/.maildir/Sent` if it is missing. read http://www.courier-mta.org/?maildirmake.html for syntax .

----------

## boudewijn

OK

just did a:

cp /home/boudewijn/.maildir ./ ; chown vmail .maildir -R

in /home/vmail/boudewijnector.nl/boudewijn.

Then did a:

```

maildirmake -f Sent ./ 
```

In the new maildir.

Everything works fine now, but I have the problem that I can't delete messages.

Added a .Trash and a .Junk folder, but this didn't solve the problem.

Again a mailbox not existing, how to find out what's that one called?

----------

## boudewijn

Another problem.... I can't receive mail  :Sad: 

It's being received by postfix: (postqueue -p)

```

5259E17820F     1609 Tue Feb  7 02:29:09  boudewijnector@gmail.com

(mailbox ///home/vmail/boudewijnector.nl/boudewijn/.maildir: cannot open file: Is a directory)

                                         boudewijn@boudewijnector.nl

50E7A17821C      591 Tue Feb  7 12:47:44  boudewijn@boudewijnector.nl

(mailbox ///home/vmail/boudewijnector.nl/boudewijn/.maildir: cannot open file: Is a directory)

                                         boudewijn@boudewijnector.nl

```

There are about 20 test-mails in the queue (only showing 2), one from a gmail account and one from my own email adress.

The directory indicated is indeed a directory:

```

/home/vmail/boudewijnector.nl/boudewijn

dionysos boudewijn # ls -al

total 16

drwxr-xr-x   4 vmail vmail 4096 Feb  7 12:43 .

drwxr-xr-x   3 vmail vmail 4096 Feb  7 01:46 ..

drwx------  10 vmail root  4096 Feb  7 12:48 .maildir

drwx------  15 vmail vmail 4096 Feb  7 10:45 maildir

dionysos boudewijn #                                    

```

Don't mind the maildir , thats just a backup, shouldn't harm (I guess?).

What's wrong? The root-group-owner shouldn't be a problem, because the direactory hasn't got group-access rights at all.

----------

## langthang

```
5259E17820F     1609 Tue Feb  7 02:29:09  boudewijnector@gmail.com

(mailbox ///home/vmail/boudewijnector.nl/boudewijn/.maildir: cannot open file: Is a directory)

                                         boudewijn@boudewijnector.nl

50E7A17821C      591 Tue Feb  7 12:47:44  boudewijn@boudewijnector.nl

(mailbox ///home/vmail/boudewijnector.nl/boudewijn/.maildir: cannot open file: Is a directory)

                                         boudewijn@boudewijnector.nl

```

because you forgot to add the trailing slash to maildir as:

```
/home/vmail/boudewijnector.nl/boudewijn/.maildir/
```

----------

## boudewijn

ah that's it.

Thanks a lot for your help!

----------

## boudewijn

Another problem, could you help me again?

I've got a user, ingrid@_NOSPAM_ector-vanleeuwen_NOSPAM_.nl (my mum, just remove _NOSPAM_ ).

When trying to connect using Thunderbird , T'Bird says "couldn't login to server <servername>". 

Also by testing using Squirrelmail , on the server I can't connect... it says "connection dropped by IMAP server" . 

This is in the mailsql DB:

```
|  7 | *@ector-vanleeuwen.nl    | * | Ingrid Ector           | 1003 | 1003 | /home/vmail | /home/vmail/ector-vanleeuwen.nl/ingrid/.maildir/

```

I've removed both the password and email-adres.

The password has been entered into both Thunderbird and squirrelmail correctly.

FYI: this is my own record, which works:

```

|  3 | *@boudewijnector.nl   | *     | Boudewijn              | 1003 | 1003 | /home/vmail | /home/vmail/boudewijnector.nl/boudewijn/.maildir/  |       | y       |

```

I've created /home/vmail/ector-vanleeuwen.nl/ingrid , and did a maildirmake on it.

Afterwards, a chown vmail:vmail -R /home/vmail did the permission-stuff.

File-permissions are the same as in my box, which works perfectly.

In my /var/log/messages ""

```

Feb 10 16:56:32 dionysos imapd: Connection, ip=[127.0.0.1]

Feb 10 16:56:32 dionysos imapd: chdir /home/vmail/ector-vanleeuwen.nl/ingrid/.maildir/ : No such file or directory

```

My permissions:

```
dionysos ingrid # pwd; ls -al

/home/vmail/ector-vanleeuwen.nl/ingrid

total 12

drwxr-xr-x  3 vmail vmail 4096 Feb 10 17:00 .

drwxr-xr-x  5 vmail vmail 4096 Feb  7 18:25 ..

drwx------  5 vmail vmail 4096 Feb 10 16:42 .maildir

dionysos ingrid # cd .maildir/

dionysos .maildir # ls -al

total 24

-rw-------  1 vmail vmail  653 Feb 10 16:42 ??

drwx------  5 vmail vmail 4096 Feb 10 16:42 .

drwxr-xr-x  3 vmail vmail 4096 Feb 10 17:00 ..

drwx------  2 vmail vmail 4096 Feb  7 18:25 cur

drwx------  2 vmail vmail 4096 Feb  7 18:25 new

drwx------  2 vmail vmail 4096 Feb  7 18:25 tmp

dionysos .maildir # 
```

This should be fine, or not (it's the same as my account, and I haven't made any stupid mistakes like last times   :Razz:  ).

----------

## langthang

 *boudewijn wrote:*   

> I've created /home/vmail/ector-vanleeuwen.nl/ingrid , and did a maildirmake on it.
> 
> Afterwards, a chown vmail:vmail -R /home/vmail did the permission-stuff. 

 

You don't have to do that. Just send an email to that account and postfix will create all folders with correct permissions. check the GID and UID of vmail. has it changed to something other than 1003 ?

----------

## boudewijn

```

dionysos .maildir # grep vmail /etc/passwd ; grep vmail /etc/group

vmail:x:1003:100::/home/vmail:/bin/false

vmail:x:1003:postfix
```

Seems like the UID+GID hasn't changed. If I think  about it, it would be quite weird because my mail (which has the same UID+GID settings) should be accessible too...

Another idea? (I've been messing with this for 2-3 days  :Sad:  )

----------

## boudewijn

*not too subtle kick*

----------

## boudewijn

nobody  knows it?

damn, I can't get any emails  :Sad: 

----------

