cosullivan / SmtpServer

A SMTP Server component written in C#
MIT License
676 stars 160 forks source link

IP address of remote endpoint is not working in filter in version 6.4.0+ #127

Closed AndriyTemplafy closed 4 years ago

AndriyTemplafy commented 4 years ago

Hi,

We use this code to validate the IP address of the sender. In version 5.3.0 where there is still a property context.RemoteEndPoint, it works and we get a valid sender IP address. But in the following code, that we tested in all versions 6.4.0, 6.5.0, 7.0.0, it always returns IP 0.0.0.0

public class ClientIpMailboxFilter : MailboxFilter
    {

        public override async Task<MailboxFilterResult> CanAcceptFromAsync(ISessionContext context, IMailbox from, int size, CancellationToken cancellationToken)
        {
            var remoteIpEndPoint = context.EndpointDefinition.Endpoint;
            if (ranges.Any(ip => ip.Contains(remoteIpEndPoint.Address)))
            {
               ...valid IP
            }
            else {
               ...invalid ip
            }
        }
    }
cosullivan commented 4 years ago

Hi @AndriyTemplafy ,

Please see the following sample as to how it can be done now. https://github.com/cosullivan/SmtpServer/blob/master/Src/SampleApp/SampleMailboxFilter.cs#L32

Thanks, Cain.

AndriyTemplafy commented 4 years ago

Thank you! This worked.