Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Utilising the Transport field - adding Relay

2012-10-10
2013-01-23
  • Simon Hobson
    Simon Hobson
    2012-10-10

    Starting to look again at properly adding Relay transport support.
    Got some queries about the SQL queries in use, and whether I should share some or duplicate them.

    As I read it, all I need to do is add a test for "transport = 'virtual'" to mysql_virtual_domains_maps.cf which is used by virtual_mailbox_domains, and create a copy of this to use with relay_domains with "transport = 'relay'".
    As I see it, I can then use the same lookups that are in virtual_alias_maps for relay_recipient_maps - thus ensuring that I can relay for any address which has an alias (whether in the domain, in an alias domain, or a catchall).

    So my virtual_mailbox_domains query will be :

    SELECT domain FROM domain WHERE domain='%s' AND transport = 'virtual' AND active = '1'
    

    And my relay_domains query will be :

    SELECT domain FROM domain WHERE domain='%s' AND transport = 'relay' AND active = '1'
    

    relay_recipient_maps queries will therefore be :

    SELECT goto FROM alias WHERE address='%s' AND active = '1'
    SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('%u', '@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
    SELECT goto FROM alias,alias_domain WHERE alias_domain.alias_domain = '%d' and alias.address = CONCAT('@', alias_domain.target_domain) AND alias.active = 1 AND alias_domain.active='1'
    

    Does this make sense ?

    BTW - I can see where the catchall for an alias domain is matched, I can't see where a catchall in a non-aliased domain is matched ? Does Postfix automatically try the alias lookup with "%s" set to "@domain" as well as trying it with "%s" set to "user@domain" ?

     
  • Simon Hobson
    Simon Hobson
    2012-10-10

    Now, I'm also wondering how to handle the situation where someone creates a domain with one transport, and an alias domain with a different transport. What's likely to happen then ?

    Initial thought is that if the alias domain says "virtual", and the real domain says "relay", then the message will be passed off to be handled by the virtual transport which will handle all the aliasing then fail when there's no mailbox record.

    The other way round, and the relay transport will simply find that the recipient is a valid address, but relay it without doing the aliased domain -> real domain translation. This shouldn't be a problem as the recipient server will need to handle both domains.

    Could be interesting working out the instruction for our tech guys !

     
  • Simon Hobson
    Simon Hobson
    2012-10-11

    Further update …

    This appears to work :)

    To answer my own questions :
    If an alias domain is setup, and the two domains are setup differently, then the target domain takes precedence. So if I receive a mail for user@domain1, and domain1 is an alias domain with a target of domain2, then the envelope gets rewritten to user@domain2.
    Then the outbound handling for the message is whatever domain2 is set to (virtual or relay).

    I have spotted one minor issue though.
    If the target domain is set to inactive, then mail will still be accepted, destination re-written, and then the mail will bounce "mail to domain2 loops back to myself".
    I've updated my *_domains_maps queries to include :

    SELECT domain FROM domain WHERE domain='%s' AND transport = 'virtual' AND active = '1' AND NOT exists (select * from alias_domain where alias_domain = '%s' AND alias_domain.active = '1')
    

    I just need to add and craft an additional map to handle alias domains - checking for all three (alias_domain, target_domain, and alias itself) being active. Job for after lunch.

     
  • Simon Hobson
    Simon Hobson
    2012-10-11

    OK, I now have a working setup.
    Probably best to do a new Wiki page for it - there's "quite a bit" of setup involved.
    Christian, time for write access to the Wiki ? BTW - is is easy to create a page without it appearing in the index until it's finished ?

     
  • (collective response to everything above)

    Does Postfix automatically try the alias lookup with "%s" set to "@domain" as well as trying it with "%s" set to "user@domain" ?

    Yes - it first tries user@domain, then @domain.

    The reason for the separate map for alias domains is to ensure the correct order/priority if a domain is aliased to another one, but also has some aliases or mailboxes on its own (which have priority).

    If the target domain is set to inactive, then mail will still be accepted, destination re-written, and then the mail will bounce "mail to domain2 loops back to myself".

    "loops back to myself" means your server has to handle the mail (based on the DNS entry), but doesn't feel responsible for it. In other words: you have to fix your DNS entry or add the domain to postfix.

    In case of alias domains, it might result in bounces instead of rejects, but I would worry more about the underlying problem ;-)

    I just need to add and craft an additional map to handle alias domains - checking for all three (alias_domain, target_domain, and alias itself) being active. Job for after lunch.

    You probably don't need new maps. Instead, you'll have to add several JOINs to the queries and check the active flag in all involved tables (domains, alias_domains, alias).

    Christian, time for write access to the Wiki ?

    You have write permissions since some minutes.

    BTW - is is easy to create a page without it appearing in the index until it's finished ?

    There is no index where pages appear automatically (except Special:Allpages), so no need to worry about this ;-)

     
  • Simon Hobson
    Simon Hobson
    2012-10-11

    You have write permissions since some minutes

    I'll start building something - I'm sure you'll spot something obvious once I get going :-/