mimefang and filter_recipient

howart
howart used Ask the Experts™
on
How can I discard messages with mimedefang and filter recipient.
If I use the sugessted method i will produce backscatter

sub filter_recipient {
    my($recip, $sender, $ip, $host, $first, $helo,
       $rcpt_mailer, $rcpt_host, $rcpt_addr) = @_;
   if ( md_check_against_smtp_server($sender, $recip,
       "muncher.poppers.local","msx-poppers.poppers.local")){
       md_syslog('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");
      return 'REJECT', "Recipient unkown" ;
    }
#    return md_check_against_smtp_server($sender, $recip,
#       "muncher.poppers.local","msx-poppers.poppers.local"); 
     return 'CONTINUE', 'ok';
}

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
What i try to do is to discard messages to unkown recipients in our domains.
When I use mimedefang  with recipient_filter messages get rejected when i try to send to an unkown recipient.

So I made  a routine in sub filter


# Check if recipient does exist on receiving mail server 
    foreach (@Recipients) {
        my($smtp_status, $smtp_message) =  md_check_against_smtp_server($Sender, $_,
        "muncher.poppers.local","msx-poppers.poppers.local");
        # print STDERR $smtp_status;
        if ( $smtp_status == 'CONTINUE' ) {
             md_graphdefang_log($smtp_status,$_,'Recipient MSX exists');
        } else {
             md_graphdefang_log('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");
             action_bounce('Unknown MSX recipient');
        }
    }

Open in new window

Author

Commented:
this does not work where am i going wrong?
Software Engineer
Distinguished Expert 2018
Commented:
Please read:
http://linux.die.net/man/5/mimedefang-filter

You will notice that you can choose from the following for dispossition of the message.
'REJECT'
    if the connection should be rejected.
'CONTINUE'
    if the connection should be accepted.
'TEMPFAIL'
    if a temporary failure code should be returned.
'DISCARD'
    if the message should be accepted and silently discarded.
'ACCEPT_AND_NO_MORE_FILTERING'
    if the connection should be accepted and no further filtering done.

So try DISCARD instead of REJECT in the original and it should disappear.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
got now this
but stil get a bounce


sub filter_recipient {
    my($recip, $sender, $ip, $host, $first, $helo,
       $rcpt_mailer, $rcpt_host, $rcpt_addr) = @_;
    # Check if recipient does exist on receiving mail server 
       my $file = "/tmp/testmd.log";
       open (FILE, ">>$file");
 
       my($smtp_status, $smtp_message) =  md_check_against_smtp_server($Sender, $recip,
                       "muncher.poppers.local","192.168.1.13");
 
       print FILE $smtp_status,$smtp_message,$Sender,$_,"\n";
       if ( $smtp_status == 'CONTINUE' ) {
            md_graphdefang_log($smtp_status,$_,'Recipient MSX exists');
            return ("CONTINUE", "");
       } else {
            md_graphdefang_log('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");
            retrun ('DISCARD', "discarded");
       }
       close(FILE);
 
}

Open in new window

Author

Commented:
I c the error
retrun instead of return
lets c if it works now

Author

Commented:
does still not work

nociSoftware Engineer
Distinguished Expert 2018

Commented:
   if ( $smtp_status == 'CONTINUE' ) {
should be:
    if ( $smtp_status eq 'CONTINUE' ) {

(== if for numeric, eq for string compares).
(it would allways be true  0 == 0.)

running perl -cw <file>

can check a file for syntax errors.

Author

Commented:
I have put the code in sub filter there it works!! :)

for some reason sub filter_recipient does not execute
Do you know what goes wrong there?

Author

Commented:
here is my code in sub filter


# Check if recipient does exist on receiving mail server 
    my $file = "/tmp/test_md_filter.log";
    open (FILE, ">>$file");
    print FILE "youre now in mimdefang-filter sub filter\n";
    foreach (@Recipients) {
        my($smtp_status, $smtp_message) =  md_check_against_smtp_server($Sender, $_,
        "muncher.poppers.local","192.168.1.13");
        print FILE $smtp_status,$smtp_message,$Sender,$_,"\n";
        # print STDERR $smtp_status;
        if ( $smtp_status eq 'CONTINUE' ) {
             md_graphdefang_log($smtp_status,$_,'Recipient MSX exists');
        } else {
             md_graphdefang_log('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");
             #action_bounce('Unknown MSX recipient');
             action_discard();
        }
    }
    close(FILE);

Open in new window

nociSoftware Engineer
Distinguished Expert 2018

Commented:
Is there no problem when opening the file?
like: /tmp/test....log owned by another user?

Maybe it is better to add
 md_syslog('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");

Calls and check the syslog output for messages.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial