How to add an email filter rule for the Body Message?

Discussion in 'Tips/Tricks/Mods' started by Outbreaker, Dec 6, 2022.

  1. Outbreaker

    Outbreaker Member

    Hi,
    I noticed that we can only setup a filter rule for the headers but not for the body content message.
    How can i ban all emails containing a specific URL in a email text message?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    You can create global filters for the body of an email, content filters in the menu of the mail module (scroll down, it's near the bottom). But you should be aware that postfix filters work on the unencoded email body.

    Creating body filters on mailbox level is also possible using custom filter rules (there is a tab for that in the mailbox), and you have to adjust the sieve template to include body filters first, but on that level, you can not reject emails anymore.
     
  3. Outbreaker

    Outbreaker Member

    Is there no option to do this without admin rights?
    No sure why the "Mail Content Filter" and "Mail Filter" have different options.
     
  4. till

    till Super Moderator Staff Member ISPConfig Developer

    No, because clients would be able to block emails for all other clients then.

    Because they are different filters that work entirely differently and get applied differently on the system.
     
  5. Outbreaker

    Outbreaker Member

    Damn a friend is getting email bombed with different email addresses and email subjects but with the same spam content.
    Even setting the spam filter to max won't work. :eek: Not sure how i can block this on the client side. :(
     
    Last edited: Dec 7, 2022
  6. till

    till Super Moderator Staff Member ISPConfig Developer

    If you are not the system's admin, then contact the admin and ask him to do something about that. Your friend can also simply use the filters of his email client to remove mails automatically.
     
  7. Outbreaker

    Outbreaker Member

    How can as a Admin then block incoming emails that contain a specific URL in the email body?
    I tried some things but i had no luck. :(
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    First, you should take a look at the raw unencoded email body to see if the URL that you try to filter out is visible there or if it is encoded. If it is visible, then you must write a regular expression to match it as Postfix email filters are regex-based, and then create a filter rule in ISPConfig with this regular expression. If the URL is not visible in the unencoded mail body, then you can create a custom sieve filter rule. ISPConfig contains the sieve body module since 3.2.9, so there is no need to alter the base sieve template anymore, you just have to write your custom sieve filter rule and add it on to the custom filter tab of the email mailbox in ISPConfig.
     
    ahrasis likes this.
  9. Outbreaker

    Outbreaker Member

    I have no luck with the "Mail Content Filter" it works for outgoing emails but not for the incoming emails.
    Mozilla Thunderbird email source:
    Code:
                                    <td width=3D"170" valign=3D"top">
                                        <img src=3D'https://external-preview.=
    redd.it/x_N0V7bhpzlFTtRpvPXcbLzJHMyCHdOqp8OYdDSGnME.jpg?width=3D640&crop=3D=
    smart&auto=3Dwebp&s=3Dbb13aaf815e7ec81c9edfe6fae83c53b801d6b19' width=3D"=
    170" height =3D "215"/>
    ISPConfig Settings:
     

    Attached Files:

  10. Outbreaker

    Outbreaker Member

    I think their is a bug in ISPConfig. The "Mail Content Filter" is only blocking outgoing mails from the server but not the incoming mails, and i can't find any other options in ISPConfig to filter text in the email body.
     
  11. till

    till Super Moderator Staff Member ISPConfig Developer

    And I'm quite sure there is no bug in that function I explained you above what the second option is to filter email body contents and where to find it. If you need help in writing and applying a filter rule, contact business support: https://www.ispconfig.org/get-support/?type=ispconfig
     
  12. Outbreaker

    Outbreaker Member

    I'm not a Business. I'm only hosting my private site and 2 sites of my friends. But i bought 2 Manuals. :confused:
    I'm really confused how this body filter should work in ISPConfig. I have already setup over 20 subject filters to reduce that spam. :eek:
     
    Last edited: Dec 8, 2022
  13. till

    till Super Moderator Staff Member ISPConfig Developer

    And we gave you ISPConfig for free, for other panels with similar functionality, you pay the equivalence of 5 manuals or more each month to use them. And helping you on this thread has cost us already about half an hour of work time or roughly 40 USD, so if we calculate this against your purchases of the manual, then ISPconfig just lost already about 30 USD in helping you out.

    That's not ISPConfig-specific at all. Postfix body filters work in the exact same way that they work on any Postfix system, no matter which control panel you use. Same with sieve body filters, not ISPConfig specific too. Works the same on any panel with a sieve-capable IMAP server like Dovecot and all you have to do is to paste the sieve rule you want to use in the custom sieve filter field of the mailbox.
     
  14. till

    till Super Moderator Staff Member ISPConfig Developer

    So, if you don't know how to write a postfix body filter regex for your problem, then use a sieve body filter instead. I mentioned that already. How to do that, use google search. I typed 'sieve body filter' in google, and this got me to this page:

    https://superuser.com/questions/1605454/sieve-rule-for-search-body

    As I mentioned above, the body module is loaded already in ISPConfig 3.2.9, so you do not need the require line. So what you need in the end is something like this:

    Code:
    if body :raw :contains "external-preview.redd.it" {
                    discard;
            }
     
    Outbreaker likes this.
  15. Outbreaker

    Outbreaker Member

    The word "sieve" confused me a bit. But i was close, i missed the ":raw :contains" code :rolleyes:
    I think in future it would be very helpful to less technical people to also have a body filter option at the settings menu "Mail Filter". :)
    That's what i use now, and it looks like it works. :D
    Code:
    if body :raw :regex "(http|https)://.*redd.it/.*.jpg" {
        reject "MESSAGE REJECTED! Your email account is being used to send spam emails. Please change your password.";
        stop;
    }
    

    Without ISPConfig I couldn't hosted any free email and webspace for some friends. My KMV-Server is also under 10 bucks. Most private persons could never afford paying for control panels like Plesk. ISPConfig give the more tech oriented people the ability to run their own email/website without being a slave to big tech. o_O I also think cooperating with some server hosters would bring in some little money, because i know from experiences that donations never really work. o_O
     
    Last edited: Dec 9, 2022
    ahrasis likes this.

Share This Page