I have an SMTPClient, using MailKit, that sends a message with the follow code.
using (var client = new SmtpClient())
{
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("localhost", 587, SecureSocketOptions.None);
client.Send(message);
client.Disconnect(true);
}
My SMTP server is implemented using cosullican/SmtpServer. I setup the server as follows:
var optionsBuilder = new SmtpServerOptionsBuilder()
.ServerName(serverName)
.Endpoint(builder =>
builder.Port(587, true)
.AllowUnsecureAuthentication(false)
.Certificate(CreateCertificate()));
var options = optionsBuilder.Build();
return new SmtpServer.SmtpServer(options, provider.GetRequiredService<IServiceProvider>());
I can't seem to get this working with StartTLS. I get a timeout when the client attempts to connect.
System.IO.IOException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
It will work when configured to not use TLS. To not use TLS the client uses SecureSocketOptions.None to connect, and for the server I remove the .Certificate line.
I think the client is setup correctly, and I am probably missing something on the server.
Note: My service is using a self-signed cert. I am developing this on my box at the moment.
How do I implement StartTLS?
I have an SMTPClient, using MailKit, that sends a message with the follow code.
using (var client = new SmtpClient())
{
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("localhost", 587, SecureSocketOptions.None);
client.Send(message);
client.Disconnect(true);
}
My SMTP server is implemented using cosullican/SmtpServer. I setup the server as follows:
var optionsBuilder = new SmtpServerOptionsBuilder()
.ServerName(serverName)
.Endpoint(builder =>
builder.Port(587, true)
.AllowUnsecureAuthentication(false)
.Certificate(CreateCertificate()));
var options = optionsBuilder.Build();
return new SmtpServer.SmtpServer(options, provider.GetRequiredService<IServiceProvider>());
I can't seem to get this working with StartTLS. I get a timeout when the client attempts to connect.
System.IO.IOException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
It will work when configured to not use TLS. To not use TLS the client uses SecureSocketOptions.None to connect, and for the server I remove the .Certificate line.
I think the client is setup correctly, and I am probably missing something on the server.
Note: My service is using a self-signed cert. I am developing this on my box at the moment.
How do I implement StartTLS?
Share Improve this question edited Mar 7 at 17:23 Don Chambers asked Mar 7 at 15:58 Don ChambersDon Chambers 4,31710 gold badges35 silver badges87 bronze badges2 Answers
Reset to default 1The problem was this line:
builder.Port(587, true)
Is should be:
builder.Port(587, false)
Setting this to true means the endpoint is secure by default and in which case it will try to update the connection to SSL when the client connects rather than waiting for the client to issue a STARTTLS command.
Change:
client.Connect("localhost", 587, SecureSocketOptions.None);
to
client.Connect("localhost", 587, SecureSocketOptions.StartTLS);
If that doesn't work, can you connect to localhost:587 using telnet?
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744919335a4601034.html
评论列表(0条)