# postfix , mysql , courier setup = cant login

## ikaro

Hi.

ive done all the setup less the webmail.

i can recieve mail from the outside using mutt, if i use other email client, like shylpheed

i cant login and get 

```

Aug 14 09:20:32 [pop3d-ssl] Connection, ip=[127.0.0.1]

Aug 14 09:20:37 [pop3d-ssl] LOGIN FAILED, ip=[127.0.0.1]

Aug 14 09:20:42 [pop3d-ssl] Unexpected SSL connection shutdown.

```

authentication failled ... iam using the info which i typed in the mysql .. beeing :

user: me@domain.dk and password : password in clear text.

i tried sending some mails to my self om me@domain.dk from my ISP email account , and then watch the logs files .. 

I can see that postfix recieves the emails.. however i cant get my hands on it .. other than using mutt ..

Ive read in other posts, and searched the forums and it seems other people had problems login in but was because of other problems, which aparently i dont have , since mail gets delivered ok.

Anyone can give me a hand on this one ?

Thanks alot !

----------

## ikaro

ok i can login now , had to fix some double lines that were in the docs and

thats suppose to be in one line , else didnt work.

however following this part about adding users:

```

 Code listing 9.1: Adding the vmail user

# adduser -d /home/vmail -s /bin/false vmail

# uid=`cat /etc/passwd | grep vmail | cut -f 3 -d :`

# groupadd -g $uid vmail

# mkdir /home/vmail

# chown vmail. /home/vmail

So now when you're setting up vmail accounts, use the vmail uid, gid, and homedir. When you're setting up local accounts, use that users uid, gid, and homedir. We've been meaning to create a php admin page for this setup but haven't gotten around to it yet, as phpmyadmin generally works fine for us.

```

Ive added the user using phpmyadmin, in the users table.

with /home/vmail/.maildir and /home/vmail

lhowever the emails get returned with such:

unknown user 

The user iam adding isnt local, and hes suppose to fetch email from the outside...

what iam missing ?

anyone can to explain this last part ?

----------

## ikaro

anyone ?

 :Embarassed: 

----------

## psp

I hope I understood you correctly and the following helps you out...

The vmail user is the only "real" user on the system that owns all virtual mail. So the 'adduser' bit adds this user.

This user _MUST_ not be in the users MySQL table.

Check your /etc/passwd to see if this user exists.

All other virtual users must be added to the database.

e.g.

For the virtual domain 'bar.com' you need to receive mail for user 'foo'. You need to add the user: foo@bar.com to the user table.

Let me know if this helps...

----------

## ikaro

hola psp  :Wink: 

Yes , the 'vmail' user isnt the in mysql users table, but only exists in the system it self, added as 'local user' with own 'home' dir ( /home/vmail)

All other users are,  indeed added to the mysql user table.

Until here we agree, so you understood me correctly.

problem: user 'test@domain.com' which is added to the mysql user table is not recognized by postfix, and therefor all mail directed to him, is returned to the sender, with 'unknown user' as reason.

My friend can however, login into the system and use the account to send email. which proves that user & password are correct and that the account is functional.

He just cant recieve email on that account, by the reason i just mentioned above.

I hope ive explained  my self better this time   :Rolling Eyes:  , well all know the feeling that

when you write something which you understand , but it might seem confusing to others. sorry about that.

----------

## kashani

I see at least one problem with your system and we may need to see some logs.

/home/vmail is not a home dir. It is a respository for home dirs. If you are truly planning to run a virtual mail system for multiple domains I would use the following format for specifying home/maildirs

/home/vmail/domain.com/username/.maildir

Using /home/vmail/.maildir as you mentioned above gives you exactly 1 possible user. Even /home/vmail/user/.maildir would be preferable though if you are going to do that, I'd skip the mysql stuff and just authenticate local users. 

If pop works and incoming smtp mail does not, my guess is that you have not told Postfix to recieve mail for that domain. Check that you've added that domain to virtual_mailbox_domains in /etc/postfix/main.cf

If the above does not work post the Postfix logs of an attempt to send email to that user.

kashani

----------

## ikaro

iam indeed using the first format , as i thought that when the virtual user was added postfix would create its home dir ( /home/vmail/domain.com/user/.maildir )

ive just checked  thats not happening ..

so im going to create that my self and try again.

----------

## ikaro

done some fixing , however i get an error :

```

Aug 14 22:10:42 [postfix/pickup] 5623A14BB1: uid=1000 from=<ikaro>

Aug 14 22:10:42 [postfix/cleanup] 5623A14BB1: message-id=<20030814201042.GA20566@ksy>

Aug 14 22:10:42 [postfix/qmgr] 5623A14BB1: from=<ikaro@domain.dk>, size=400, nrcpt=1 (queue active)

Aug 14 22:10:42 [postfix/virtual] 5623A14BB1: to=<test@domain.dk>, relay=virtual, delay=0, status=deferred (recipient test@domain.dk: bad uid -uid in virtual_uid_maps)

```

the uid/gid ive used are the same as the vmail user, like its described in the docs.

user: test@domain.dk

home: /home/vmail

maildir: /home/vmail/domain.dk/test/.maildir

```

ikaro@ksy ikaro $ id vmail    

uid=1007(vmail) gid=100(users) groups=100(users)

```

the uid/gid are 100% correct .. so how come postfix says its wrong ? 

btw , local user account can send/recieve email w/out problem.. this is only happening with the virtual accounts.

other than that , everything is working 100%

thanks

----------

## kashani

Make sure that all subdirs are owned by vmail

chown -R vmail. /home/vmail/

Also I had some similar errors until I tweaked the config. Below is what worked for me.

virtual_minimum_uid = 1000

virtual_gid_maps = mysql:/etc/postfix/mysql-virtual-gid.cf

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

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

virtual_uid_maps = mysql:/etc/postfix/mysql-virtual-uid.cf

virtual_mailbox_base = /

kashani

----------

## psp

Looks like the map for your UID/GID is b0rked.

If you only intend to use one UID for all your virtual domain's mail, then you might as well use a 'static' map.

```

# my UID/GID for the user vmail = 1004

# uid=1004(vmail) gid=1004(vmail) groups=1004(vmail)

virtual_uid_maps = static:1004

virtual_gid_maps = static:1004

```

This lookup is also the least 'expensive' and quickest.

Give this a try and see if it helps.

----------

## ikaro

hi .

ok did some more tweaking, i do not get that "unknown user" error anymore and the mail gets delivered.

however .....

it gets delivered into a file called '.maildir' and not a directory '.maildir' like its suppose to do.

so, when the user uses the email client to fect email, gets pop3 error: Maildir not a dir.

if i intervine manually, and remove the file named .maildir and turn that into a dir, then , emails cant get delivered :

```

Aug 15 11:06:41 [postfix/virtual] A262314BB2: to=<test@domain.dk>, relay=virtual, delay=0, status=deferred (mailbox ///home/vmail/domain.dk/test/.maildir: cannot open file: Is a directory)

```

main.cf

```

smtpd_sasl_auth_enable = yes

smtpd_sasl2_auth_enable = yes

smtpd_sasl_security_options = noanonymous

broken_sasl_auth_clients = yes

smtpd_sasl_local_domain =

smtpd_recipient_restrictions =

        permit_sasl_authenticated,

        permit_mynetworks,

        reject_unauth_destination

smtpd_use_tls = yes

#smtpd_tls_auth_only = 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

local_transport = local

local_recipient_maps = $alias_maps $virtual_mailbox_maps unix:passwd.byname

virtual_transport = virtual

virtual_mailbox_domains = domain.dk

virtual_minimum_uid = 1000

#virtual_gid_maps = static:$vmail-gid

virtual_gid_maps = mysql:/etc/postfix/mysql-virtual-gid.cf

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

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

#virtual_uid_maps = static:$vmail-uid

virtual_uid_maps = mysql:/etc/postfix/mysql-virtual-uid.cf

virtual_mailbox_base = /

#virtual_mailbox_limit =

```

Thank you once again  :Smile: 

----------

## psp

Make sure the directory name ends with a '/'

e.g.

/home/vmail/somedomain.com/someuser/.maildir/ <-- this slash is important!

The slash at the end tells postfix to deliver to a maildir, no slash indicates a mbox file.

----------

## ikaro

ok that got fixed .

Thank you very much for the help.all of you.

----------

## psp

No problem...

----------

