cosullivan / SmtpServer

A SMTP Server component written in C#
MIT License
692 stars 163 forks source link

Get hostname value of EHLO/HELO command #132

Closed bertsinnema closed 4 years ago

bertsinnema commented 4 years ago

Hi There,

Is there a possibility to get the value of the HELO/EHLO command that is entered by the connecting client?

It would be nice if HELO somedomain.com would set somedomain.com as the clients' hostname in ISessionContext.

I want to use the domain name to do DANE-EE verification which relies on a TLSA record that is set for the hostname. I can do a PTR (reverse DNS) lookup with the connecting IP address but it will fail when the connecting client has no PTR record.

cosullivan commented 4 years ago

Hi,

The way you can do this at the moment is to trace the commands that are executing in the session. If you have a look at the sample here; https://github.com/cosullivan/SmtpServer/blob/master/Src/SampleApp/Examples/SessionTracingExample.cs

There is an event you can attach to on the Session that is fired on each command that is being executed. In your event handler you could do something like this;

if (e.Command is EhloCommand ehloCommand) { e.Context.Properties.Add("DomainOrAddress", ehloCommand.DomainOrAddress); }

And that would then be available in the session context during the call to your IMailboxFilter or IMessageStore.

Hopefully that should give you what you need.

bertsinnema commented 4 years ago

Hi Cain,

Thanks for getting back to me. This gets me what I need for a lot of other scenarios too.

Cheers!