# postfix+postgresql virutal accounts



## graudeejs (Jan 29, 2010)

Heck, i've been trying to figure this out for 2 days now....
I managed to get working most of parts of my mail server...

But there's 2 issues....  going to ask only 1 for now...

I've set up postfix... and it works until I try to use virtual accounts.
sql lookup seams to work fine {well virtual aliases work}

but the problem is when i try to send mail to virtual user mail doesn't get delivered


```
# mailq
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
8621B895D       267 Fri Jan 29 21:55:56  root@bsdroot.lv
                                                       (unknown user: "aldis")
                                         aldis@bsdroot.lv

-- 0 Kbytes in 1 Request.
```

I don't understand how to make postfix aware of virtual accouns....


/var/log/maillog

```
Jan 29 21:55:17 rootbsd postfix/master[18296]: terminating on signal 15
Jan 29 21:55:17 rootbsd postfix/postfix-script[18541]: starting the Postfix mail system
Jan 29 21:55:17 rootbsd postfix/master[18542]: daemon started -- version 2.6.5, configuration /usr/local/etc/postfix
Jan 29 21:55:17 rootbsd postfix/qmgr[18544]: 74C7288F4: from=<killasmurf86@gmail.com>, size=2949, nrcpt=1 (queue active)
Jan 29 21:55:17 rootbsd postfix/local[18547]: 74C7288F4: to=<aldis@bsdroot.lv>, orig_to=<root@bsdroot.lv>, relay=local, delay=328, 
delays=328/0.02/0/0.03, dsn=4.1.1, status=SOFTBOUNCE (unknown user: "aldis")
Jan 29 21:55:22 rootbsd dovecot: dovecot: Killed with signal 15 (by pid=0 uid=0 code=)
Jan 29 21:55:22 rootbsd dovecot: Dovecot v1.2.10 starting up
Jan 29 21:55:22 rootbsd dovecot: auth(default): pgsql: Connected to mail
Jan 29 21:55:43 rootbsd postfix/postsuper[18592]: 7123C8886: removed
Jan 29 21:55:43 rootbsd postfix/postsuper[18592]: 74C7288F4: removed
Jan 29 21:55:43 rootbsd postfix/postsuper[18592]: 68C2C8885: removed
Jan 29 21:55:43 rootbsd postfix/postsuper[18592]: Deleted: 3 messages
Jan 29 21:55:56 rootbsd postfix/pickup[18543]: 8621B895D: uid=0 from=<root>
Jan 29 21:55:56 rootbsd postfix/cleanup[18599]: 8621B895D: message-id=<20100129195556.8621B895D@bsdroot.lv>
Jan 29 21:55:56 rootbsd postfix/qmgr[18544]: 8621B895D: from=<root@bsdroot.lv>, size=267, nrcpt=1 (queue active)
Jan 29 21:55:56 rootbsd postfix/local[18547]: 8621B895D: to=<aldis@bsdroot.lv>, orig_to=<root>, relay=local, delay=0.07, delays=0.06/0/0/0.01, 
dsn=4.1.1, status=SOFTBOUNCE (unknown user: "aldis")
Jan 29 22:05:17 rootbsd postfix/qmgr[18544]: 8621B895D: from=<root@bsdroot.lv>, size=267, nrcpt=1 (queue active)
Jan 29 22:05:17 rootbsd postfix/local[18672]: 8621B895D: to=<aldis@bsdroot.lv>, orig_to=<root>, relay=local, delay=561, delays=561/0.02
/0/0.03, dsn=4.1.1, status=SOFTBOUNCE (unknown user: "aldis")
Jan 29 22:12:08 rootbsd postfix/postfix-script[18740]: stopping the Postfix mail system
Jan 29 22:12:08 rootbsd postfix/master[18542]: terminating on signal 15
Jan 29 22:12:08 rootbsd postfix/postfix-script[18814]: starting the Postfix mail system
Jan 29 22:12:08 rootbsd postfix/master[18815]: daemon started -- version 2.6.5, configuration /usr/local/etc/postfix
```

nothing show in /var/log/messages


EDIT
I've read a ton of info... I even tried to read howto in German. lol.


----------



## ohauer (Jan 31, 2010)

can you show a `# postconf -n`.

Im special interested in 


mydestination
mydomain
relay_domains
virtual_alias_domains
virtual_mailbox_domains
masquerade_domains


----------



## graudeejs (Jan 31, 2010)

I'll show as soon as I can


----------



## gkontos (Jan 31, 2010)

There i an excellent guide on installing postfix with mysql and Dovecot. I have used parts of it for my production mail server and it works perfectly. I suppose that you could adjust it for postgresql or you can definitely get a good idea.

George


----------



## graudeejs (Jan 31, 2010)

```
# postconf -n
broken_sasl_auth_clients = yes
command_directory = /usr/local/sbin
config_directory = /usr/local/etc/postfix
daemon_directory = /usr/local/libexec/postfix
data_directory = /var/db/postfix
debug_peer_level = 2
home_mailbox = Maildir/
html_directory = /usr/local/share/doc/postfix
inet_interfaces = $myhostname
mail_owner = postfix
mailq_path = /usr/local/bin/mailq
manpage_directory = /usr/local/man
mydestination = $myhostname, localhost.$mydomain, localhost
mydomain = bsdroot.lv
myhostname = bsdroot.lv
mynetworks_style = host
myorigin = $mydomain
newaliases_path = /usr/local/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = /usr/local/share/doc/postfix
sample_directory = /usr/local/etc/postfix
sendmail_path = /usr/local/sbin/sendmail
setgid_group = maildrop
smtp_tls_note_starttls_offer = yes
smtp_use_tls = yes
smtpd_recipient_restrictions = permit_mynetworks	permit_sasl_authenticated	reject_unauth_destination
smtpd_sasl_auth_enable = yes
smtpd_sasl_path = private/auth
smtpd_sasl_security_options = noanonymous
smtpd_sasl_type = dovecot
smtpd_tls_CAfile = /etc/ssl/postfix/smtpd.pem
smtpd_tls_cert_file = /etc/ssl/postfix/smtpd.pem
smtpd_tls_key_file = /etc/ssl/postfix/smtpd.pem
smtpd_tls_loglevel = 0
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
smtpd_use_tls = yes
soft_bounce = yes
unknown_local_recipient_reject_code = 550
virtual_alias_maps = pgsql:/usr/local/etc/postfix/pgsql_virtual_alias_maps.cf
virtual_gid_maps = pgsql:/usr/local/etc/postfix/pgsql_virtual_gid_maps.cf
virtual_mailbox_base = /mail
virtual_minimum_uid = 1000
virtual_transport = dovecot
virtual_uid_maps = pgsql:/usr/local/etc/postfix/pgsql_virtual_uid_maps.cf
```


----------



## ohauer (Jan 31, 2010)

It seems you don't have a user aldis configured or as valid recipient.

Sorry hope bsdroot.lv is really your machine, I've just done a small test (you can find my name in your logs)



> mail from: <ohauer(_at_)DoNotTell.TLD>
> 250 2.1.0 <ohauer(_at_)DoNotTell.TLD>... Sender ok
> rcpt to: <aldis(_at_)bsdroot.lv>
> 550 5.7.1 <aldis(_at_)bsdroot.lv>... Relaying denied
> ...




If you have all user accounts for bsdroot.lv in the virtual_alias_maps, then try the following


```
mydestination = localhost.$mydomain, localhost
virtual_alias_domains = bsdroot.lv
```


----------



## graudeejs (Jan 31, 2010)

ad, dam sorry man....
I started configuring it all from strach, and deleted previous config entirely....

Yes, server is my.... postix not configured yet..., sorry, I will let you know here, when I get beck to where I was [hopefully this time it will Just Work (tm)]


----------



## ohauer (Jan 31, 2010)

> I started configuring it all from strach, and deleted previous config entirely....



Hm, my feeling with your config was you need only a view adjustments..

A hint before starting with everything DB based.
Configure postfix without dovcot and keep config in hash or cdb files.
If everything is working move to DB usage and then include dovcot.


Maybe a good side for info in english http://postfix.wiki.xs4all.nl/

Maybe take also a look into postfixadmin.


----------



## graudeejs (Feb 1, 2010)

```
# postconf -n
command_directory = /usr/local/sbin
config_directory = /usr/local/etc/postfix
daemon_directory = /usr/local/libexec/postfix
data_directory = /var/db/postfix
debug_peer_level = 2
home_mailbox = Maildir/
html_directory = /usr/local/share/doc/postfix
inet_interfaces = $myhostname
local_recipient_maps = $virtual_mailbox_maps
mail_owner = postfix
mailq_path = /usr/local/bin/mailq
manpage_directory = /usr/local/man
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
mydomain = bsdroot.lv
myhostname = bsdroot.lv
mynetworks_style = host
myorigin = $mydomain
newaliases_path = /usr/local/bin/newaliases
queue_directory = /var/spool/postfix
readme_directory = /usr/local/share/doc/postfix
sample_directory = /usr/local/etc/postfix
sendmail_path = /usr/local/sbin/sendmail
setgid_group = maildrop
soft_bounce = yes
unknown_local_recipient_reject_code = 550
virtual_mailbox_base = /mail
virtual_mailbox_maps = pgsql:/usr/local/etc/postfix/pgsql_virtual_mailbox_maps.cf
virtual_minimum_uid = 1001
virtual_transport = virtual
virtual_uid_maps = pgsql:/usr/local/etc/postfix/pgsql_virtual_uid_maps.cf
```


----------



## ohauer (Feb 2, 2010)

Is it now working as you expect? (you don't have virtual_aliases defined as before)

http://www.postfix.org/VIRTUAL_README.html#virtual_alias.

If you want to have this with virtual, then remove $mydomain from mydestination and configure it as virtual, see post before

```
mydestination = localhost.$mydomain, localhost <- without $myhostname and $mydomain
virtual_alias_domains = bsdroot.lv
```


----------



## graudeejs (Feb 2, 2010)

thanks for tip....
I'll check that....

In new bsdmag issue, there is howto postifx+postgresql+dovecot.... I'll read that


----------



## graudeejs (Feb 2, 2010)

I'm not 100% sure how, but I solved this {thanks to bsdmag}


----------

