cosullivan / SmtpServer

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

Server hangs when using STARTTLS #138

Closed nkalfov closed 3 years ago

nkalfov commented 3 years ago

Hi,

I am currently trying to use the library in a NETCORE 3.1 Windows Service on port 25 over STARTTLS. However, the client gets stuck on connecting. I downloaded the source and debugged the library, it seems the server itself is getting stuck when UpgradeAsync of SmtpServer.IO.NetworkStream is invoked. Does the library support STARTTLS? This could be related to Issue #108 However, I am not using a self-signed certificate and I do trust the certificate authority. I can't connect with STARTTLS to port 587 either. Plain and SSL/TLS are OK, though. But I do need STARTTLS.

nkalfov commented 3 years ago

I've actually found the issue. I was doing:

        var options = new SmtpServerOptionsBuilder()
            .ServerName(host)
            .Certificate(cert)
            .Endpoint(builder =>
                builder
                    .Port(port)
                    .IsSecure(isSecure)
                    .AllowUnsecureAuthentication(false)
                    .AuthenticationRequired(false))
            .MessageStore(new SmtpMessageStore())
            .Build();

But I should do:

var options = new SmtpServerOptionsBuilder()
            .ServerName(host)
            .Certificate(cert)
            .Endpoint(builder =>
                builder
                    .Port(port))
            .UserAuthenticator(new DoNothingUserAuthenticator())
            .MessageStore(new SmtpMessageStore())
            .Build();

Then, I start the connection and upgrade it with STARTTLS.