Menu

#34 change SMTP status code for rejected mails

closed
None
5
2023-11-12
2023-09-25
No

Hi,

is there any way to send different SMTP response code to clients after running the filters?
its needed in filtering mode because 452 code causes retry in mail server side but 5xx codes not.

in gsmtp/gsmtpserversend.cpp file you comment it but not implemented.

void GSmtp::ServerSend::sendCompletionReply( bool ok , const std::string & response )
{
    if( ok )
        sendOk( "message processed" ) ;
    else
        // 452=>"action not taken", or perhaps 554=>"transaction failed" (so don't try again)
        send( "452 " + response ) ;
}

my suggestion; if exit code is 1 or any other value or range return 550/554 otherwise return 452

Discussion

  • Graeme Walker

    Graeme Walker - 2023-09-25

    Yes, it makes sense to allow the filter to choose between 4xx and 5xx, but I think I would prefer to use the error response text rather than the exit code. The response that the filter prints to stdout inside double angle brackets or double square brackets could then be "<<554 rejected>>".

    The required code changes would intersect with this https://sourceforge.net/p/emailrelay/support-requests/88/#108c which is now on the V_2_5_1 branch.

     
  • Yunus YILDIRIM

    Yunus YILDIRIM - 2023-09-25

    error response is ok, agree and I'm using.
    but, as you know smtp clients use these codes.
    if I return 4xx code to mail server after filter result it will try it again and again but when I send 5xx code it not try again.
    so as result, allow the filter to choose SMTP code would be good like response text.

     
  • Graeme Walker

    Graeme Walker - 2023-09-25

    I think you mis-understood. I am proposing a change that allows the filter to choose the response code by extending the existing mechanism used for the response text.

    Instead of this (in a shell-script filter):

    echo '[[failed]]'
    exit 1 # sends "452 failed"
    

    you can do this:

    echo '[[550 failed]]'
    exit 1 # sends "550 failed"
    
     
  • Graeme Walker

    Graeme Walker - 2023-09-26

    Patch attached for the sf V_2_5_1 branch.

     
  • Yunus YILDIRIM

    Yunus YILDIRIM - 2023-09-26

    I tested emailrelay-2.5p1.exe and emailrelay-2.5p2.exe with below filter;

    echo off
    set arg1=%1
    set arg2=%2
    :: just test content/envelope arguments
    
    echo [[550 Rejected for policy reasons]]
    exit 1
    

    but the response code same, it just add my code as response text;

    452 550 Rejected for policy reasons
    

    also I test filter with network filter on socket but the response same.
    am I miss any detail?

     

    Last edit: Yunus YILDIRIM 2023-09-26
  • Yunus YILDIRIM

    Yunus YILDIRIM - 2023-09-27

    excellent. it worked.
    Thanks a lot.

     
  • Yunus YILDIRIM

    Yunus YILDIRIM - 2023-10-24

    hi again,
    when I try to do same thing with network filter its not work.

    I try to send "[[550 Rejected for policy reasons]]" or "<<550 Rejected for policy reasons>>" as response over socket. the emailrelay return "452 [[[550 Rejected for policy reasons]]" as response.

    also I try to send "550 Rejected for policy reasons" as response and SMTP code not work too.
    this message return "550 550" as SMTP code and message. not my error message with SMTP code

     

    Last edit: Yunus YILDIRIM 2023-10-25
  • Graeme Walker

    Graeme Walker - 2023-10-30

    The network filter does not use double angle-bracket or double square-bracket delimiters. (The reason for them is because the scripting run-time can emit all sorts of junk that is not under the script's control -- like the microsoft copyright banners.) In a network filter just send "550 rejected" or whatever without the brackets.

     
  • Yunus YILDIRIM

    Yunus YILDIRIM - 2023-10-30

    I try this one also, as I said in previous message, but it didnt work.
    in attachment you will see my response over network filter and smtp server message. also I add my simple python network filter script

     
  • Graeme Walker

    Graeme Walker - 2023-10-30

    The relevant code was committed on September 27th. Is your test executable later that that?

     
  • Yunus YILDIRIM

    Yunus YILDIRIM - 2023-10-30

    yes. filename is emailrelay-2.5.1rc2.exe
    here is therelevant emailrelay log lines;

    emailrelay-2.5.1rc2: 20231030.094547.021: info: 1.2.3.4; GStore::NewFile: new envelope file [emailrelay.8036.1698648347.17.envelope.new]
    emailrelay-2.5.1rc2: 20231030.094556.193: info: 1.2.3.4; GSmtp::ProtocolMessageStore::filterDone: filter [127.0.0.1/10101/ip]: [emailrelay.8036.1698648347.17]: failed response=[550 ] reason=[550 Rejected content]
    emailrelay-2.5.1rc2: 20231030.094556.193: info: 1.2.3.4; GSmtp::ProtocolMessageStore::filterDone: rejected by filter: [550 Rejected content]
    emailrelay-2.5.1rc2: 20231030.094556.194: info: 1.2.3.4; GSmtp::ServerSend: tx>>: "550 550 "
    emailrelay-2.5.1rc2: 20231030.094556.195: info: 1.2.3.4; GSmtp::ServerProtocol: rx<<: "QUIT"
    emailrelay-2.5.1rc2: 20231030.094556.195: info: 1.2.3.4; GSmtp::ServerSend: tx>>: "221 OK"
    emailrelay-2.5.1rc2: 20231030.094556.195: info: 1.2.3.4; GSmtp::ServerPeer: smtp connection closed: smtp protocol done: 1.2.3.4:49461
    
     
  • Graeme Walker

    Graeme Walker - 2023-10-30

    Okay, thanks for testing: there is a bug on line 129 of gnetworkfilter.cpp. The erase() should have zero as its first parameter.

     
  • Yunus YILDIRIM

    Yunus YILDIRIM - 2023-11-09

    hi,
    will be any release for this one?

     
  • Graeme Walker

    Graeme Walker - 2023-11-10

    It's ready for release, except that I wanted to rework the windows build procedure before publishing binaries. It's not going particularly well, so I think I'll revert that and hopefully get the release out over the weekend.

     
  • Graeme Walker

    Graeme Walker - 2023-11-12
    • status: open --> closed
     
  • Graeme Walker

    Graeme Walker - 2023-11-12

    Now released.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.