1 (edited by MW 2021-02-01 04:07:20)

Topic: Why does this iRedAPD plugin trigger the error "loops back to myself"

==== REQUIRED BASIC INFO OF YOUR IREDMAIL SERVER ====
- iRedMail version (check /etc/iredmail-release): latest 1.3
- Deployed with iRedMail Easy or the downloadable installer? downloadable
- Linux/BSD distribution name and version: Ubuntu 18
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? no
- [IMPORTANT] Related original log or error message is required if you're experiencing an issue.
====

I have this plugin:

from libs import SMTP_ACTIONS

SMTP_PROTOCOL_STATE = ['RCPT', 'END-OF-MESSAGE']

def restriction(**kwargs):

    size = kwargs['smtp_session_data']['size']

    if size:
        size = int(size)
    else:
        size = 0

    if size < 10485760: # message size smalled than 10 MB
        return SMTP_ACTIONS['default'] # which basically relays emails to external SMTP server (as configured in main.cf)
    else: # it is bigger
        return 'FILTER smtp:'

This is working fine except when a user with a domain hosted on my iRedMail server (first-domain.com) sends a big email (bigger than 10 MB) to a user under another domain hosted on my iRedMail server (second-domain.com), then delivery fails with postfix complaining that message loops to itself.

What is going wrong here? Thank you.

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Why does this iRedAPD plugin trigger the error "loops back to myself"

MW wrote:

        return 'FILTER smtp:'

With "smtp:", it enters the postfix queue again, and it's a loop. This is the cause.
I guess you want smtp action "REJECT" to reject the message like below?

return "REJECT Message size too large"

REJECT is the action, the rest words are optional text to explain why we reject it. Note: end user will see the text.

3

Re: Why does this iRedAPD plugin trigger the error "loops back to myself"

I guess you want smtp action "REJECT" to reject the message like below?

No, I don't want to reject it, if it is bigger than 10 MB (i.e. the condition) I want it to be delivered by the local SMTP server and not relayed (i.e. to skip the relayhost configured inside /etc/postfix/main.cf).

4

Re: Why does this iRedAPD plugin trigger the error "loops back to myself"

You must specify the smtp address and port. e.g.:

FILTER smtp:[192.168.0.1]:25

5

Re: Why does this iRedAPD plugin trigger the error "loops back to myself"

ZhangHuangbin wrote:

You must specify the smtp address and port. e.g.:

FILTER smtp:[192.168.0.1]:25

I do that like this:

FILTER smtp:[127.0.0.1]:25

But I am getting the error:

554 5.4.0 Error: too many hops (in reply to end of DATA command)

What I am trying to do is to use my local SMTP server (skipping the realyhost if message size is bigger than 10 MB).

6

Re: Why does this iRedAPD plugin trigger the error "loops back to myself"

Isn't it obvious that using "smtp:[127.0.0.1]:25" is looping again and again?

You can try to add a new smtp port in Postfix master.cf with "relayhost=" (with empty value) and it should be used only for this situation (FILTER).

7

Re: Why does this iRedAPD plugin trigger the error "loops back to myself"

ZhangHuangbin wrote:

Isn't it obvious that using "smtp:[127.0.0.1]:25" is looping again and again?

You can try to add a new smtp port in Postfix master.cf with "relayhost=" (with empty value) and it should be used only for this situation (FILTER).

I have tried your suggestions like this:

26      inet  n       -       y      -       -       smtpd
  -o syslog_name=postfix/twentysix
  -o smtpd_tls_security_level=encrypt
  -o smtpd_sasl_auth_enable=yes
  -o smtpd_client_restrictions=permit_mynetworks,permit_sasl_authenticated,reject
  -o relayhost= 

But getting:

host 127.0.0.1[127.0.0.1] said: 554 5.4.0 Error: too many
    hops (in reply to end of DATA command)