Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a custom EndpointListener via Dependency Injection #195

Closed
idblew opened this issue Apr 20, 2023 · 1 comment
Closed

Adding a custom EndpointListener via Dependency Injection #195

idblew opened this issue Apr 20, 2023 · 1 comment

Comments

@idblew
Copy link

idblew commented Apr 20, 2023

Related to #140

How do you add a custom EndpointListener when using Dependency Injection?

Also I see that IEndpointListener now requires GetPipeAsync rather than GetStreamAsync, is there a simple example of filtering on IP address using the new interface?

@cosullivan
Copy link
Owner

Hi,

There are two ways you can do this now.

Firstly, you can listen for the SessionCreated event on the SmtpServer instance and check the IP address from there. The default EndpointListener will add the IP address to the session context (check out the SessionTracingExample). If you get an IP address that you want to block, you can simply throw an exception here and the client will be disconnected and closed.

The second option is similar to before whereby you can create a custom endpoint listener. From within the custom endpoint listener, get the underlying Pipe and you can dispose of that and return null.

Thanks, Cain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants