0

I had installed Posfix, Dovecot and MySQL on Debian (for example sample.net) and configured its that external users are allowed to send mails only on this domain sample.net (using my SMTP). Also I configured that all mails (like *@sample.net) are forwarded to one mailbox bulk@sample.net. Mostly I was following this guide.

Some my Postfix configuration:

virtual_alias_maps = proxy:mysql:/etc/postfix/mysql-virtual_forwardings.cf

mysql-virtual_forwardings.cf
query = SELECT destination FROM forwardings WHERE source='%s'

Table
| SOURCE | destination |
| @sample.net | bulk@sample.net |

I’ve allowed my SNTP to receive only mails for sample.net by next way:

transport_maps = proxy:mysql:/etc/postfix/mysql-virtual-transport.cf

mysql-virtual-transport.cf
query = SELECT transport FROM transport WHERE DOMAIN='%s'

Table
| DOMAIN | transport |
| sample.net | : |
| * | error:Only allowing one domain |

All work as I expected but I need add possibility to send mails from local clients (like PHP) to external users. Unfortunately I have no ideas how I can do it.

MadHatter
  • 79,770
  • 20
  • 184
  • 232
Victor
  • 111
  • 4
  • I think you're going about this wrong, you should just set `mydestination` to be `sample.net`, then allow relaying from `mynetworks`, usually 127.0.0.1 and a selection of hosts connected in the same subnet.. – NickW Mar 07 '14 at 10:58

2 Answers2

1

The default settings in postfix are to disallow relaying to anybody from outside the machine, and also only accept mail for domains hosted locally.

With that in mind, what you want to achieve is fairly straightforward. You should set mydestination like this (assuming that the postfix server is in sample.net)

mydestination = $myhostname localhost.$mydomain localhost

Set myhostname to the hostname of the server something like mail.sample.net and mydomain to sample.net

That will ensure that from the "outside" postfix will only accept mail for sample.net, then you can set up an alias to redirect all mail to sample.net to bulk@sample.net

Then you can set mynetworks to allow forwarding only from itself like this:

mynetworks = 127.0.0.0/8

This will do everything you asked for, and is much more flexible. You will probably need to do things like setting up an MX record, RDNS, and possibly other things that are beyond the scope of this answer.

NickW
  • 10,263
  • 1
  • 20
  • 27
  • Thank you very much. Actually I've realized that I chose a quite weird way to achieve my goal. I'll try to reconfigure the server in this way. – Victor Mar 07 '14 at 16:00
1

Absolutely brilliant guide to set up email server with postfix, dovecot and mysql can be found here: https://workaround.org/ispmail/wheezy

I've worked through it twice, once with Debian and the components mentioned there and once with Ubuntu, with slightly different versions of postfix and dovecot and with postgres instead of mysql.

Reading the guide and understanding it worth every minute spent and I always recommend it to people, even if they are going to have a smaller setup.

Roman Grazhdan
  • 334
  • 3
  • 15