Koozali.org: home of the SME Server

Limit the sending of emails only to certain domains (internal to external)

Offline Sergio Piñon

  • *
  • 14
  • +0/-0
Greetings from Chihuahua, Mexico. I'm new to Linux and SME server. I have a question as I do to limit the sending of emails only to certain domains (internal to external). I already have some time with this, reading and studying the manuals and testing the Contribs but I have not managed. Any tip is very grateful.

Online mmccarn

  • *
  • 2,656
  • +10/-0
I am completely guessing here, but this might work:

Code: [Select]
mkdir -p /etc/e-smith/templates-custom/var/qmail/control/smtproutes
cd /etc/e-smith/templates-custom/var/qmail/control/smtproutes

# replace domainA.org, domainB.org, etc with your desired allowed domains
echo 'domainA.org:localhost:26
domainB.org:localhost:26
domainC.org:localhost:26
:localhost:9999
' > 20SMTPSmartHost

signal-event email-update

Undo this change (if it causes problems) using:
Code: [Select]
rm -f /etc/e-smith/templates-custom/var/qmail/control/smtproutes/20SMTPSmartHost
signal-event email-update

What this is doing:

The default qmail config causes qmail to forward all email to localhost:26 -
Code: [Select]
# cat /var/qmail/control/smtproutes
...
:localhost:26

I'm trying to include working settings for the specific domains you want to communicate with, while providing a broken/nonfunctioning default(:localhost:9999) for everything else.

More on qmail smtproutes / qmail-remote:
http://wiki.qmailtoaster.com/index.php/Smtproutes
http://www.qmail.org/man/man8/qmail-remote.html




Offline Sergio Piñon

  • *
  • 14
  • +0/-0
Thank you very much for the information, now it works for me blocked all of which seems an excellent progress, however the domains that if they are configured in the 20SMTPSmartHost are also not sent, I see that port 26 I do not have it enabled. To enable it, what would it do? change 25 to 26 in the smtpd service? Thanks again.

Online mmccarn

  • *
  • 2,656
  • +10/-0
If you are using an smtpsmarthost for relay you'd need to customize var/qmail/control/smtproutes/20SMTPSmartHost.

The default output (with a smarthost), sends all email to the smarthost:
Quote from: var/qmail/control/smtproutes/20SMTPSmartHost
...
            $OUT .= ":$SMTPSmartHost";
...

To relay only your selected domains, you would need to add the domains in front of the colon, and remove the default route shown above.

This would do it:
Code: [Select]
mkdir -p /etc/e-smith/templates-custom/var/qmail/control/smtproutes/
cd /etc/e-smith/templates-custom/var/qmail/control/smtproutes/
# note the dot at the end of the next command...
cp /etc/e-smith/templates/var/qmail/control/smtproutes/20SMTPSmartHost .

Now edit the "custom" copy of 20SMTPSmartHost to list only your desired domains:
Quote from: /etc/e-smith/templates-custom/var/qmail/control/smtproutes/20SMTPSmartHost
{
    $OUT = "";

    #--------------------------------------------------
    # Now check for SMTP smart host
    #--------------------------------------------------

    if (
        $SMTPSmartHost
        &&
        ($SMTPSmartHost ne 'off')
        &&
        ($SMTPSmartHost !~ /^\s*$/)
    )
    {
        # Is the smtp-auth-proxy enabled?
        if (${'smtp-auth-proxy'}{'status'} eq 'enabled')
        {
            $OUT .= ":localhost:26";
        }
        else
        {
            $OUT .= "domainA.org:$SMTPSmartHost";
            $OUT .= "domainB.org:$SMTPSmartHost";
            $OUT .= "domainC.org:$SMTPSmartHost";

        }
    }

    chomp ($OUT);
}


SME is designed to allow persistent, safe override of default settings using this mechanism - a fragment inside .../templates-custom/... with the same name and path as a fragment inside .../templates/... will override and disable the original fragment. Learn more at https://wiki.contribs.org/Template_Tutorial

Activate the changes:
Code: [Select]
signal-event email-update

Removing the new file in ".../templates-custom/..." will re-enable the default settings (in case your changes cause unexpected problems):
Code: [Select]
rm -f /etc/e-smith/templates-custom/var/qmail/control/smtproutes/20SMTPSmartHost
signal-event email-update

Offline Sergio Piñon

  • *
  • 14
  • +0/-0
Thank you very much !!, finally it works as I wanted it, thanks to your valuable comments I understood things of SME that I had no idea what can be done and that I just started...