# Postfix + sasl + courier + mysql, doesn't work

## T-Hawk

Following the tutorial on http://www.gentoo.org/doc/en/virt-mail-howto.xml I have tried to setup postfix including virtual users using mysql.

Appearantly however it doesn't authenticate against the mysql database, I have the domain called t-hawk.com and have tried to setup a virtual user named taddr@t-hawk.com adding it to the users table, using the vmail user and mailbox.

However whenever I try to mail this virtual user postfix reports back that the user doesn't exists.

It is also not possible to login using the username / password provided in the database.

Any help will be appreciated, and any log files and likewise can be supplied

-T-Hawk

----------

## bwoo

did you add your domain into the transport table? This is usually the one step most people forget to do.

----------

## T-Hawk

I'm not entirely positive on what to put into the transport table. I have an entry:

```

/-------------------------------\

| id | domain     | destination |

|----|------------|-------------|

|  1 | t-hawk.com | local:      |

\-------------------------------/

```

But could it then be a problem that the user taddr doesn't exist on the local computer? and if so how would I create virtual users on the local domain?

----------

## kashani

You'd want to change local: to virtual: unless you're trying to authenticate against system users rather than virtual users. Also you need to add your domain to mydestination.

kashani

----------

## T-Hawk

I have now updated t-hawk.com from local: to virtual: however nothing happens... I can still authenticate users on t-hawk.com using the local password and mail for taddr won't deliver?  :Confused:   :Crying or Very sad: 

----------

## bwoo

what is the username you're using? taddr or taddr@t-hawk.com (try it with the full email address as the user name)

b

----------

## T-Hawk

If I use taddr it says username or password incorrect, if I use taddr@t-hawk.com it says "ERROR : Connection dropped by imap-server." if I try to login using squirrelmail... And if I mail the address taddr@t-hawk.com it says that the user was not found and bounces the mail.

----------

## T-Hawk

Using another mail client I could see that it was due to a missing .maildir that I couldn't login to the virtual account... I copied this from /etc/skel/.maildir and it is now possible to login to the account. However postfix still bounces and says "unknown user: "taddr""

----------

## bwoo

Usually with all the Postfix Virtual Hosting how-to's (of which I know of at least 4 for Debian/Gentoo), when using a virtual user, you need to specify the entire email address as the username. (Sorry for harping on with that, but I know that was a huge issue for me when I was setting up, and none of the how-to's actually stress that).

----------

## T-Hawk

yeah tried that. And as posted above I'm now able to login to the account over atleast POP3, haven't tried IMAP but would guess that wouldn't be a problem. It's now only a prob sending mail to the user, if I send mail to taddr@t-hawk.com postfix bounces the mail and says that it can't find the user.

In the main.cf file I have to following settings for virtual:

```

# grep 'virtual' main.cf

local_recipient_maps = $alias_maps $virtual_mailbox_maps unix:passwd.byname

virtual_transport = virtual

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

virtual_minimum_uid = 1000

virtual_gid_maps = static:100

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

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

virtual_uid_maps = static:1002

virtual_mailbox_base = /

#virtual_mailbox_limit =

# mysql-virtual.cf

user      = mailsql

password   = <password>

dbname      = mailsql

table      = virtual

select_field   = destination

where_field   = email

hosts      = unix:/var/run/mysqld/mysqld.sock

# mysql-virtual-maps.cf

user      = mailsql

password   = <password>

dbname      = mailsql

table      = users

select_field   = maildir

where_field   = email

additional_conditions = and postfix = 'y'

hosts      = unix:/var/run/mysqld/mysqld.sock

```

----------

## T-Hawk

Okay it seems the problem might be that the domain t-hawk.com is specified in main.cf as $mydomain and that postfix tries only a local user then.

Is is somehow possible to have the local domain using virtual users as well? Or could I perhaps create virtual users and then use the virtual table to redirect postfix to something say like: taddr@t-hawk.com -> taddr@virtual

Or something like that?

----------

## T-Hawk

Can't anybody help me? Please.... (Oh no a bump...  :Wink: )

----------

## toralf

My biggest mistake was not to redefine the value MYSQL_USER_TABLE in /etc/courier/authlib/authmysqlrc. I left the default value "mysql" whereas I defined all mail users with their passwords in my mysql-database named "courier".

BTW to track down the error test your email system using a real UNIX user and use only "authmodulelist="authpam authshadow" in /etc/courier/authlib/authdaemonrc to verify that the connection to mysql is wrong and nothing else. In addition set "log = /var/log/mysql/mysql.log" in /etc/mysql/my.cnf to see the mysql actions.

----------

## T-Hawk

It is possible to send mail to unix accounts, have tried several different unix accounts. When logging I can see the following query:

```
select maildir from users where email = 'taddr@t-hawk.com' and postfix = 'y'
```

which correctly returns the maildir, this is rather confusing as postfix insists on not finding the user.

----------

## dblaci

Use only virtual domains, no need to add to transport table, and mydestination should be different than the domain you use.

I made my configuration based on that howto, and it worked. Now i modified some things for example ther is a domain table for the virtual domains.

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

 *Quote:*   

> 
> 
> user            = sqluser
> 
> password        = passxy
> ...

 

But i'm not sure this will fix your problem, but it's a good thing if you host multiple domains.

----------

