accepting only known email addresses as inbound - relay_recipient map

Request and discuss new features you would like to have.
Post Reply
jens
Posts: 9
Joined: 25 Feb 2017 22:50

accepting only known email addresses as inbound - relay_recipient map

Post by jens »

Hello,

after
relay_domains = hash:/etc/postfix/transport

i put
relay_recipient_maps = hash:/etc/postfix/relay_recipient

into main.cf

this way all mails to unused addresses are immediately rejected with

Recipient address rejected: User unknown in relay
recipient table (in reply to RCPT TO command)

As EFA already knows all my users and aliasses (filters) this should be an option in efa instead of manualy create the relay_recipient file


thank,
jens
jens
Posts: 9
Joined: 25 Feb 2017 22:50

Re: accepting only known email addresses as inbound - relay_recipient map

Post by jens »

Hello

Better using a mysql query as mysql is enabled in postfix:

postconf -m
...
mysql
...

This way it could be used with AD sync as well

The trick here ist a UNION statement in as we have 2 diffrent tables for users and alias emails
for a nice explanation look at https://workaround.org/ispmail/jessie/postfix-mysql


in main.cf add
relay_recipient_maps = mysql:/etc/postfix/mysql_relay_recipients.cf


The file mysql_relay_recipients.cf

Code: Select all

# The user name and password to log into the mysql server.
## maybe the values can somehow extracted from /etc/EFA-Config
hosts = localhost
user = mailwatch
password = password
dbname = mailscanner
query = select 1 FROM users WHERE username = '%s' UNION SELECT 1 from user_filters WHERE filter = '%s';

Test if it works:

Code: Select all

postmap -q existing@example.com mysql:/etc/postfix/mysql_relay_recipients.cf
gives result 1

Code: Select all

postmap -q not-existing@example.com mysql:/etc/postfix/mysql_relay_recipients.cf
no result


to list all email addresses from users and filter you can use the following querry

Code: Select all

SELECT username  FROM  users WHERE username like '%@%' UNION SELECT  filter from user_filters WHERE filter like '%@%' ;

kind regards,
jens
Post Reply