4

I am setting up a mail server using Postfix+Dovecot on RHEL7. Though it is not required, I would like to set it up such that the mail server is able of hosting multiple domains.

The problem that arose is that I have two domain names that are absolutely synonymous: at some point in the past an alternative name was introduced to save users a few keystrokes. All emails that exist with one domain name also exist with the other. I want emails going to these two domains be delivered into the same mailboxes. I would like to avoid hard-rewriting the addresses to one spelling: if a user sends an email from the address that includes the long domain name, the email should appear as such upon delivery, same about shorter email addresses.

  1. Postfix is configured to relay mails to these two domains

    # in /etc/postfix/main.cf
    relay_domains = hash:/etc/postfix/relay_domains
    
    # in /etc/postfix/relay_domains
    my-long-named-domain.com   lmtp:unix:private/lmtp-dovecot
    mydomain.com               lmtp:unix:private/lmtp-dovecot
    
  2. Postfix outsources authentication to Dovecot via Dovecot SASL

    Authentication and mail delivery work for logins with short user@mydomain.com and fail for long logins user@my-long-named-domain.com throwing a message User does not exist. I guess this happens because of paths, that are explained in 3 and 4.

  3. Dovecot uses passwd-file mechanism for userdb and passdb, where %d is used in file paths to differentiate between domains.

    # in /etc/dovecot/conf.d/auth-passwdfile.conf.ext
    passdb {
        driver = passwd-file
        args = scheme=CRYPT username_format=%n /etc/dovecot/%d/users
    }
    
    userdb {
        driver = passwd-file
        args = username_format=%n /etc/dovecot/%d/users
        default_fields = uid=vmail gid=vmail
    }
    

    The users file is located under short domain name only: /etc/dovecot/mydomain.com/users.

  4. The mail_location parameter also uses %d:

    mail_location = maildir:/var/vmail/%Ld/%Ln/Maildir
    

Question: Is there a way to map the long domain name to the short one and do it only for this specific pair of domains? I want all mails for these two domains be delievered to maiboxes with shorter mydomain.com:

   /var/vmail/mydomain.com/user1/Maildir
   /var/vmail/mydomain.com/user2/Maildir
   /var/vmail/mydomain.com/user3/Maildir

Should it be done in Postfix or in Dovecot?

I know I can create soft/hard links to ensure both directories exist, but I dislike this solution (absolutely!).

In general, what is the correct approach to solving this problem? I am rather newbie in mail server stuff.

Thanx

Nik O'Lai
  • 181

1 Answers1

0

Instead of using relay_domains you could use virtual_alias_domains & virtual_alias_maps to point the long form to the short form:

@my-long-named-domain.com       @mydomain.com

You can read virtual(5) for more information, or there are tons of howto's for the fine details of using virtual aliases in Postfix.

Here's a to-the-point one if virtual(5) is too dense for a first course: https://www.mind-it.info/2013/10/23/setting-virtual-alias-domains-correctly-postfix/