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

Get client IP address while client connects to smtp server? #130

Closed
iredmail opened this issue Dec 16, 2020 · 7 comments · Fixed by #146
Closed

Get client IP address while client connects to smtp server? #130

iredmail opened this issue Dec 16, 2020 · 7 comments · Fixed by #146

Comments

@iredmail
Copy link
Contributor

iredmail commented Dec 16, 2020

Dear @emersion

First of all, thanks for the great work. 👍

We're trying to implement an internal SMTP server, and we'd like to reject client as earlier as possible if client IP address is not whitelisted. Currently it's ok to get client IP in Mail() method of Session interface, but we'd like to reject it even earlier. For example, when the client connects to the smtp server.

Could you share some idea of how we can achieve this? Thank you. :)

@emersion
Copy link
Owner

Maybe we could add a Serve.ServeConn(c net.Conn) function like x/net/http2 has? An alternative would be to add hooks to the Server configuration like net/http has.

Note, you should already be able to do this by implementing a custom net.Listener that filters incoming connections, however it's somewhat boilerplate-y.

@iredmail
Copy link
Contributor Author

iredmail commented Dec 16, 2020

  1. Is it better / easier to add a new method for the Session struct? e.g. Connect(addr net.Addr) error, it's called when client connected.
  2. Another question: we want to reply with a short message, how to send reply to client like conn.WriteResponse()? i mistakenly used return &smtp.SMTPError{...} even it returns 200 smtp code, client considers it's a failure. :(

@Savageman
Copy link

Sorry to intrude, But I'm interested in the same kind of feature for the Helo command, if it can help.

The session is not yet created at connection time (neither Login() or AnonymousLogin() was called). Maybe this hook to the Backend interface instead?

@emersion
Copy link
Owner

Can you open a new issue an explain your use-case?

@foxcpp
Copy link
Collaborator

foxcpp commented Jul 20, 2021

There is no way to terminate the connection on NewSession though. That's probably can be done via #147. Needs discussion.

@emersion
Copy link
Owner

Wouldn't an error returned by NewSession terminate the connection?

@foxcpp
Copy link
Collaborator

foxcpp commented Jul 20, 2021

It will return an error response to the client without terminating the connection. Client can issue EHLO/HELO/QUIT in this case.

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

Successfully merging a pull request may close this issue.

4 participants