User disconnect from any event. - WeOnlyDo Discussion board

User disconnect from any event. (wodSmtpServer / wodPop3Server / wodImapServer)

by ajitpals, Friday, February 05, 2016, 13:25 (3003 days ago)

Hi,

I'm currently disconnecting user in mail_from event with hard deny and sending the message back to the user in case of error. Something like this.

void mSMTP_MailFrom(SmtpUser User, ref string Address, ref SmtpActions Action)
{
//In case any error.
if(anyerror){
Action = SmtpActions.Deny;
User.Send(disconnectReason);
Thread.Sleep(100);
User.Disconnect();
return;
}
}

On telent, user get disconnected and message is seen on the command prompt.But the sending from email server like office 365 i didn't get any error message back or disconnect reason and servertried again to send the message back to the SMTP connection from different connection, even after i have denied it.

Is this alright or i'm missing something in code?

Thanks,
Ajit

User disconnect from any event.

by Jasmine, Friday, February 05, 2016, 13:28 (3003 days ago) @ ajitpals

Hi Ajit.

Using sleep in event, in single-threaded environment, is not a good idea. It stops everything, even socket processing. So, messag enever reaches remote.

You set Action to Deny, but disconnect user before he receives a message.

Don't Sleep, don't Disconnect. Just Deny. User will have to leave anyway, or try to re-register with the server.

Jasmine.

User disconnect from any event.

by ajitpals, Friday, February 05, 2016, 13:32 (3003 days ago) @ Jasmine

Hi Ajit.

Using sleep in event, in single-threaded environment, is not a good idea. It stops everything, even socket processing. So, messag enever reaches remote.

You set Action to Deny, but disconnect user before he receives a message.

Don't Sleep, don't Disconnect. Just Deny. User will have to leave anyway, or try to re-register with the server.

Jasmine.

So this should work

if(anyerror){
User.Send(disconnectReason);
Action = SmtpActions.Deny;
return;
}

does it close the session automatically for user?

User disconnect from any event.

by Jasmine, Friday, February 05, 2016, 13:34 (3003 days ago) @ ajitpals

No, this is not correct.

If you will use User.Send, then Action should be SilentDeny, otherwise wodSmtpServer will also send a message.

It will not auto-disconnect user. You must give it some spare time for your data to leave the socket. But, there's no specific reason to disconnect him anyway - he can not send new email, he can only try to with new MAIL FROM, where you will intercept it again.

If you wish, you can check in some timer a second later and disconnect the user.

Jasmine.

User disconnect from any event.

by ajitpals, Monday, February 08, 2016, 11:46 (3000 days ago) @ Jasmine

No, this is not correct.

If you will use User.Send, then Action should be SilentDeny, otherwise wodSmtpServer will also send a message.

It will not auto-disconnect user. You must give it some spare time for your data to leave the socket. But, there's no specific reason to disconnect him anyway - he can not send new email, he can only try to with new MAIL FROM, where you will intercept it again.

If you wish, you can check in some timer a second later and disconnect the user.

Jasmine.

Hi ,

I have tried following settings as described, in Case any error. I'm calling the following code,


Mail_From Event(){
If(anyError){
Action = SmtpActions.Deny;
return;
}
}

It seems to work and socket is disconnect after 1 - 2 minute in between. But server is still trying 2 connect and send messages? Should send error code in User.Send() like 550, 547? To make sure server, don't make retry.


Thanks,
Ajitpal

User disconnect from any event.

by Jasmine, Monday, February 08, 2016, 12:23 (3000 days ago) @ ajitpals

Hi Ajitpal,

I think on SilentDeny/Deny we do send out 5xx messages. Question is why server is still trying.. I cannot be sure.

You can, if you wish, set SilentDeny and use User.Send("5xx....") message to be sure, but it's up to remote server to decide if it will retry.

It shouldn't.. But.. Well, if it's some sort of spam message, anything can happen.

Best regards,
Jasmine.