cosullivan / SmtpServer

A SMTP Server component written in C#
MIT License
675 stars 159 forks source link

Tracking Session activity; is there a Session identifier anywhere? #189

Closed BrewingCoder closed 8 months ago

BrewingCoder commented 1 year ago

when using autenticators, messagestores, and events I'd like a way to understand what session is being used for logging/tracking purposes. Typically in the past I've done this with account/time based logic but in my current situation a clients with the same username could open simultaneous sessions.

I solved this temporarily by adding the following line to the SmtpSessionContext constructor which seems to have the proper lifecycle:

Properties.Add("ID",Guid.NewGuid());

However I'm not sure how this aligns with your roadmap or if there is a better alternative that I'm missing.

cosullivan commented 8 months ago

Hi,

I've specifically left these types of functionality up to the consumer, so your solution is somewhat correct, however, you can do this by attacking it to the session when the session is first created.

Have a look at the SessionTracingExample as I've just modified that to do the same thing but external to making changes to the component. It listens for the SessionCreated event on the Server itself.

Thanks, Cain.