roehling / postsrsd

Postfix Sender Rewriting Scheme daemon
324 stars 39 forks source link

SRS_INCLUDE_DOMAINS - Only specific domains make use of SRS #42

Closed ev0lister closed 5 years ago

ev0lister commented 9 years ago

Hi there,

I do have an enhancement suggestion: Maybe it's worth to have a variable telling that I only want to have specific domains make use of SRS. Imagine I have some distribution lists created by using postfix and redirects (e.g. list@lists.server.com) then I maybe just want to have lists.server.com make use of SRS.

Basically a feature where I can define which domain makes use of SRS would be great.

Thanks for the good work! Stefan

bjoe2k4 commented 9 years ago

The default is to rewrite all domains except the ones excluded. Your feature requires changing the default.

I would recommend you to modify the *_canonical_maps directives by prepending another map that does this job, e.g. a mysql map. This way you should be able to obtain what you want.

ev0lister commented 9 years ago

Thanks! That seems to be working - have created a mysql query to check whether a mailbox for specific mail exists. If so, no SRS will be done (as no forwarding in this case is needed).

langemeijer commented 9 years ago

Could you share your configuration with us?

ev0lister commented 9 years ago

Sure. Here you have the extended postfix configuration. Please note that mysql should be working already.

sender_canonical_maps = mysql:/etc/postfix/no-srs.cf, tcp:127.0.0.1:10001
sender_canonical_classes = envelope_sender
recipient_canonical_maps = mysql:/etc/postfix/no-srs.cf, tcp:127.0.0.1:10002
recipient_canonical_classes= envelope_recipient,header_recipient

in /etc/postfix/no-srs.cf we have the following

user = vmail
password = XXXXX
hosts = 127.0.0.1
dbname = vmail
query = SELECT CONCAT(username, '@', domain) FROM users WHERE username='%u' AND domain='%d'

Table users stores my mailboxes on my server. So if this query returns a valid string e.g. mail@box.com then SRS will not be executed. In case it does not, normal SRS takes place. You may have to adapt this to your datastructure etc. in the end you just need to have the valid email as a string forwarded to postfix. This will then be stored as Return-To: header. Hope this explains it a bit.

roehling commented 8 years ago

This is a very nice solution, thank you for that. As a small optimization, you can omit the MySQL query from the recipient_canonical_maps, since it will only reverse-rewrite addresses which have been rewritten previously. Therefore, anything that would match with the MySQL query would be left unchanged anyway.

ev0lister commented 8 years ago

Good point, thanks. For reference, the map for recipient looks like this then (again): recipient_canonical_maps = tcp:127.0.0.1:10002 recipient_canonical_classes= envelope_recipient,header_recipient

level420 commented 8 years ago

@ev0lister sorry for kicking in: It seems that this does not work on my setup with postfix 2.10.1 (centos7). The query works, but rewriting stops for all senders. I've one difference in my config. I'm using the query through proxymap like this:

sender_canonical_maps = proxy:mysql:/etc/postfix/maps/virtual_no_srs_maps.cf, tcp:127.0.0.1:10001

Does this make any difference?

level420 commented 8 years ago

Sorry for the noise! It works as expected!

@ev0lister Thank you for this solution! Great!

Regards Dietrich

level420 commented 8 years ago

@ev0lister Does it matter which string ist returned by the query? Could this also be something like 'true'?

Regards Dietrich

roehling commented 8 years ago

@level420 Yes, it matters. The result of the query becomes the new address.

level420 commented 8 years ago

@roehling Thank you for clarifying. But this is simple anyway, as we have %d and %u and I can use %d to select the domain from the database and concat the result with %u.

pmimark commented 7 years ago

We are using postfix as an MTA and Postfix is forwarding the original email.

So we need to re-write the headers to match the envelope.

For example in forwarded email at From Address it showing to:rohitbhaskar4u@gmail.com.mageupgradeservice.com.

I only need rohitbhaskar4u@gmail.com to display to user at the same.

Thank you in Advance...

roehling commented 5 years ago

Closing this issue, since it seems to be stale. Feel free to reopen.

natan64 commented 5 years ago

I testesd and testesd with postfix-3.3.x and I have a problem:

sender_canonical_maps=hash:/etc/postfix/maps, tcp:127.0.0.1:10001 sender_canonical_classes=envelope_sender recipient_canonical_maps=hash:/etc/postfix/maps, tcp:127.0.0.1:10002 recipient_canonical_classes = envelope_recipient,header_recipient

Every time hash:/etc/postfix/maps was ignoring and all go to postsrsd

cat maps:

ala@domain.ltl ala@domain.ltd

I use ver 1.5

benchonaut commented 1 year ago

sender_canonical_maps = mysql:/etc/postfix/no-srs.cf, tcp:127.0.0.1:10001

<3 .. thank you

HINT: did not work on aliases , so the final statement was:

query = SELECT IFNULL((SELECT source FROM aliases WHERE source='%u@%d' LIMIT 1),(SELECT CONCAT(username, '@', domain) FROM users WHERE username='%u' AND domain='%d') )