Koozali.org: home of the SME Server

Blocking Bad Mail From To

Offline ReetP

  • *
  • 3,731
  • +5/-0
Blocking Bad Mail From To
« on: October 30, 2019, 01:15:38 PM »
OK - following on from some other threads here, here's a quicky on how to block specific mails using the BadMailFromTo plugin.

There is no warranty with this. It MAY have unintended consequences so beware !!

A typical example we have is where several companies belong to a 'group' and use a shared newsletter hoster eg emailgun or similar

When you receive a mail it will have a line like this

Code: [Select]
dispatching MAIL FROM:<bounce+c3f563.7fcf54-user=ourdomain.co.uk@someservice.com>
BUT.

The 'From' line showing in the mail client will be say:

sales@someprintingcompany.com

We could block someservice.com entirely but we do want some emails, just not all.

Here's how to block it on the 'From' address you can see in the email client.

Note that I am using templates-custom + one config entry.

Code: [Select]
nano /etc/e-smith/templates-custom/var/service/qpsmtpd/config/plugins/31badmailfromto
Paste this:

Code: [Select]
{
    return "# BadMailFromTo disabled" unless (${qpsmtpd}{BadMailFromTo} eq "enabled");
    "badmailfromto";
}

And save.

Next:

Code: [Select]
cd /etc/e-smith/templates-custom/var/service/qpsmtpd/config/peers/0
ln -s ../../plugins/31badmailfromto 31badmailfromto

Data goes in this file. Note the From and To must be tab separated:

Code: [Select]
nano /var/service/qpsmtpd/config/badmailfromto
Use this format where <tab> means insert a TAB with the tab key !

From<tab>To

Code: [Select]
mytestaccount@gmail.com<tab>user@mydomain.co.uk
Now we need to fire it all up:

config setprop qpsmtpd BadMailFromTo enabled
signal-event email-update

Try a test mail from the gmail account.

Quote
** Message not delivered **

There was a problem delivering your message to user@mydomain.co.uk. See the technical details below.

The response from the remote server was:
550 mail to user@mydomain.co.uk not accepted here

Fabulous !!

To disable set BadMailFromTo <> enabled and email-update.

I might see if I can add a little DB to add addresses and formats the /var/service/qpsmtpd/config/badmailfromto file properly.

« Last Edit: October 30, 2019, 07:57:41 PM by ReetP »
...
1. Read the Manual
2. Read the Wiki
3. Don't ask for support on Unsupported versions of software
4. I have a job, wife, and kids and do this in my spare time. If you want something fixed, please help.

Bugs are easier than you think: http://wiki.contribs.org/Bugzilla_Help

If you love SME and don't want to lose it, join in: http://wiki.contribs.org/Koozali_Foundation