# Postfix virtual users

## Ward

I'm trying to configure my postfix with virtual users.

Now I made my databases but i can't login! with normal users it works but with virtual not. There is some error with a query. 

I've included config file, database setup,error so you have an idea

Thanks!

main.cf

```

queue_directory = /var/spool/postfix

command_directory = /usr/sbin

daemon_directory = /usr/lib/postfix

mail_owner = postfix

myorigin = localhost

myhostname = eddy.be

mydestination = eddy.be, localhost, localhost.Belkin, Belkin

unknown_local_recipient_reject_code = 450

mynetworks_style = subnet

mynetworks = 127.0.0.0/8 192.168.2.0/24

mailbox_command = /usr/bin/procmail

debug_peer_level = 3

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

manpage_directory = /usr/share/man

readme_directory = /usr/share/doc/postfix-2.1.5-r2/readme

default_destination_concurrency_limit = 2

alias_database = hash:/etc/mail/aliases

local_destination_concurrency_limit = 2

alias_maps = hash:/etc/mail/aliases

home_mailbox = .maildir/

smtpd_sasl_auth_enable = yes

smtpd_sasl_security_options = noanonymous

smtpd_sasl_local_domain =

broken_sasl_auth_clients = yes

smtpd_client_restrictions = permit_sasl_authenticated, reject_unauth_destination

smtpd_use_tls=yes

smtpd_tls_auth_only = yes

smtpd_tls_key_file = /etc/ssl/postfix/server.key

smtpd_tls_cert_file = /etc/ssl/postfix/server.crt

smtpd_tls_CAfile = /etc/ssl/postfix/server.pem

smtpd_tls_loglevel = 3

smtpd_tls_received_header = yes

smtpd_tls_session_cache_timeout = 3600s

tls_random_source = dev:/dev/urandom

#virtual_alias_maps=mysql:/etc/postfix/mysql_virtual_alias_maps.cf

virtual_mailbox_maps=mysql:/etc/postfix/mysql-virtual_mailboxes.cf

#virtual_mailbox_base=/usr/local/virtual

virtual_transport = virtual

virtual_uid_maps=static:5000

virtual_gid_maps=static:5000

virtual_mailbox_domains = mysql:/etc/postfix/mysql_virtual_domains_maps.cf

```

mysql_virtual_alias_maps.cf

```

user = root

password = *

hosts = localhost

dbname = postfix

table = alias

select_field = goto

where_field = address

```

mysql_virtual_domains_maps.cf

```

user = root

password = *

hosts = localhost

dbname = postfix

table = domain

select_field = domain

where_field = domain

```

mysql-virtual_mailboxes.cf

```

user = root

password = *

hosts = localhost

dbname = postfix

table = mailbox

select_field = maildir

where_field = username

```

my postfix database

```

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

| Tables_in_postfix |

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

| admin             |

| alias             |

| domain            |

| domain_admins     |

| log               |

| mailbox           |

| vacation          |

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

7 rows in set (0.00 sec)

```

Alias Table

```

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

| address              | goto                                      | domain      | created             | modified            | active |

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

| abuse@localhost      | abuse@change-this-to-your.domain.tld      | localhost   | 2000-01-01 01:29:50 | 2000-01-01 01:29:50 |      1 |

| hostmaster@localhost | hostmaster@change-this-to-your.domain.tld | localhost   | 2000-01-01 01:29:50 | 2000-01-01 01:29:50 |      1 |

| postmaster@localhost | postmaster@change-this-to-your.domain.tld | localhost   | 2000-01-01 01:29:50 | 2000-01-01 01:29:50 |      1 |

| webmaster@localhost  | webmaster@change-this-to-your.domain.tld  | localhost   | 2000-01-01 01:29:50 | 2000-01-01 01:29:50 |      1 |

| test@spamstop.be     | test@spamstop.be                          | spamstop.be | 2000-01-01 01:51:05 | 2000-01-01 01:51:05 |      1 |

| test@eddy.be         | test@eddy.be                              | eddy.be     | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |      1 |

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

```

Domain table

```

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

| domain      | description   | aliases | mailboxes | maxquota | transport | backupmx | created             | modified            | active |

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

| localhost   | -             |       0 |         0 |        0 | virtual   |        0 | 2000-01-01 01:29:50 | 2000-01-01 01:29:50 |      1 |

| spamstop.be | spamstop test |       0 |         0 |        0 | virtual   |        0 | 2000-01-01 01:50:43 | 2000-01-01 01:50:43 |      1 |

| eddy.be     |               |       0 |         0 |        0 | virtual   |        0 | 0000-00-00 00:00:00 | 0000-00-00 00:00:00 |      1 |

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

3 rows in set (0.00 sec)

```

Mailbox Table

```

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

| username         | password                           | name | maildir                   | quota | domain      | created             | modified            | active |

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

| test@spamstop.be | $1$e40dd70b$cvT4gKIrB4KbsK5RVg1WV0 |      | test@spamstop.be/         |     0 | spamstop.be | 2000-01-01 01:51:05 | 2000-01-01 01:51:05 |      1 |

| test@eddy.be     | test                               | test | /var/virtual/eddy.be/test |     0 | eddy.be     | 2006-11-30 00:00:00 | 2006-11-22 00:00:00 |      1 |

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

```

messages

```

Jan  1 01:26:08 eddy postfix/virtual[5748]: fatal: bad string length 0 < 1: virtual_mailbox_base =

Jan  1 01:26:09 eddy postfix/master[5357]: warning: process /usr/lib/postfix/virtual pid 5748 exit status 1

Jan  1 01:26:09 eddy postfix/master[5357]: warning: /usr/lib/postfix/virtual: bad command startup -- throttling

Jan  1 01:27:01 eddy pop3d: Connection, ip=[::ffff:192.168.2.2]

Jan  1 01:27:01 eddy pop3d: LOGIN, user=esger, ip=[::ffff:192.168.2.2]

Jan  1 01:27:01 eddy pop3d: LOGOUT, user=esger, ip=[::ffff:192.168.2.2], top=0, retr=0, time=0

Jan  1 01:27:01 eddy pop3d: Connection, ip=[::ffff:192.168.2.2]

Jan  1 01:27:01 eddy pop3d: LOGIN FAILED, user=test, ip=[::ffff:192.168.2.2]

Jan  1 01:27:06 eddy pop3d: Disconnected, ip=[::ffff:192.168.2.2]

Jan  1 01:27:09 eddy postfix/virtual[5753]: fatal: bad string length 0 < 1: virtual_mailbox_base =

Jan  1 01:27:10 eddy postfix/master[5357]: warning: process /usr/lib/postfix/virtual pid 5753 exit status 1

Jan  1 01:27:10 eddy postfix/master[5357]: warning: /usr/lib/postfix/virtual: bad command startup -- throttling

```

----------

## magic919

Needs:

```

virtual_mailbox_base = /what/ever/it/is 

```

----------

## Ward

 *magic919 wrote:*   

> Needs:
> 
> ```
> 
> virtual_mailbox_base = /what/ever/it/is 
> ...

 

how does it work then ? he makes the dir with:

/what/ever/it/is  + maildir field in mysql table mailbox

?

----------

## geaaru

Try with

virtual_mailbox_base = /var/spool/mail/

If i remember correctly is mailbox/maildir directory where postfix save messages.

If it works said me..  :Smile: 

good work!

----------

## magic919

 *Ward wrote:*   

>  *magic919 wrote:*   Needs:
> 
> ```
> 
> virtual_mailbox_base = /what/ever/it/is 
> ...

 

Yes, that's it.  Postfix then knows where to start creating the directories and maildirs for the virtual users.  I made the directory by hand on mine.

----------

## Ward

I've changed this in my main.cf

```
virtual_mailbox_base= /var/virtual/eddy.be/
```

and the path exists with a map test for my test user!

In the mailbox table in the test@eddy.be record the mailbox field is set to test

```

Jan  1 21:19:49 eddy postfix/trivial-rewrite[5773]: warning: do not list domain eddy.be in BOTH mydestination and virtual_mailbox_domains

Jan  1 21:19:50 eddy postfix/smtpd[5814]: NOQUEUE: reject: RCPT from unknown[192.168.2.2]: 450 <test@eddy.be>: Recipient address rejected: User unknown in local recipient table; from=<ward@loockx.be> to=<test@eddy.be> proto=SMTP helo=<test>

Jan  1 21:20:01 eddy cron[5825]: (root) CMD (test -x /usr/sbin/run-crons && /usr/sbin/run-crons )

```

Now I get this error but I saw that the domain (eddy.be) is added to my domains table so what is wrong?

----------

## geaaru

Try also this options on main.cf file:

comment myorigin voice because it is used default myhostname field.

then try to set

```

inet_interfaces = all

mydestination = $myhostname, localhost

virtual_minimum_id = 5000

# Generate maildirsize files or not

virtual_create_maildirsize = yes

# I use Courier IMAP compatibles files.

virtual_maildir_extended = yes

```

and then verify your /etc/hosts files if it contains eddy.be name

----------

## Ward

 *geaaru wrote:*   

> Try also this options on main.cf file:
> 
> comment myorigin voice because it is used default myhostname field.
> 
> then try to set
> ...

 

Changed it and my hosts file contains my eddy.be record but still it isn't working

----------

## geaaru

Always same errors from log?

----------

## Ward

 *geaaru wrote:*   

> Always same errors from log?

 

yes

```
Dec  2 18:32:58 eddy postfix/smtpd[24162]: NOQUEUE: reject: RCPT from unknown[192.168.2.2]: 450 <test@eddy.be>: Recipient address rejected: User unknown in local recipient table; from=<ward@loockx.be> to=<test@eddy.be> proto=SMTP helo=<lol>
```

----------

## magic919

Notice that it thinks test@eddy.be is a LOCAL user.  Should be a virtual user.

Heed the Postfix error message and take it out of mydestination.

----------

## Ward

 *magic919 wrote:*   

> Notice that it thinks test@eddy.be is a LOCAL user.  Should be a virtual user.
> 
> Heed the Postfix error message and take it out of mydestination.

 

Ok this works thank you

But know he complains about a dir! that's my maildir for the test account and it's created! So why doesn't he put the mail in there ? what file does he needs to open?

```

Jan  3 07:18:56 eddy postfix/virtual[5823]: 7B7A12D802: to=<test@eddy.be>, relay=virtual, delay=228, status=deferred (mailbox /var/virtual/eddy.be/test: cannot open file: Is a directory)

```

----------

## magic919

Let Postfix create that directory and it should be fine.

----------

## Ward

```
(mailbox /var/virtual/eddy.be/test: cannot create file exclusively: Permission denied)
```

i've try'd chmod +xwr but wont work

----------

## magic919

Sounds like you might have permissions/ownership problem with /var/virtual/.

----------

## Ward

Everything works good know except for one thing 

I can't login to my virtuals user accounts with mailclients or command line!

I still get

```
Dec  4 23:11:40 eddy pop3d: LOGIN FAILED, user=test@eddy.be, ip=[::ffff:192.168.2.2]

Dec  4 23:11:45 eddy pop3d: Disconnected, ip=[::ffff:192.168.2.2]
```

I've watched for a wrong query but can't find one or mistake with user table (mailbox table)

----------

## magic919

This is not a Postfix problem as Postfix does not serve up the POP mail.  Start a new thread with details of your POP server.

----------

