STARTTLS support?

I'm struggling a bit with a VB.Net 2005 app that requires SMTP STARTTLS support, both from the client (initiating) and from the server (receiving) side.
STARTTLS allows email clients and servers to begin with a non-encrypted TCP/IP session and then "upgrade" the connection using encrypted TLS upon the client issuing the STARTTLS command.
I believe I can use the standard socket class and then overlay the SSLStream class, also bringing in the certificate class.
Thanks for any insights, code snippets, etc. that you may have.
-Jim
[559 byte] By [jimadams] at [2008-3-3]
# 1

Are you using the System.Net.Mail.SmtpClient object? It sounds like you are implementing your own SMTP client on top of Sockets. Our SmtpClient Object supports SSL and TLS already, so you shouldn't have to do anything with STARTTLS other than just set a boolean property to true.

JonCole at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2

Note, System.Net.Mail.SmtpClient is new to V2.0 of the .Net Framework.

JonCole at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 3

I have the same problem. Here's my code:

System.Net.Mail.MailMessage M = new System.Net.Mail.MailMessage("<From>", "<To>");
M.Subject = "Hello there!";
M.Body = "If you can read this then it works!";
System.Net.Mail.SmtpClient SMTPClient = new System.Net.Mail.SmtpClient();
System.Net.NetworkCredential basicAuthentication = new System.Net.NetworkCredential("<Account>", "<Password>");

SMTPClient.Host = "<MyHostName>";
SMTPClient.UseDefaultCredentials = false;
SMTPClient.Credentials = basicAuthentication;

SMTPClient.Send(M);*Causes error

*Error "Syntax error, command unrecognized. The server response was: 5.7.3 Must issue a STARTTLS command first "

I can telnet to my exchange server, enter EHLO followed by STARTTLS and I get "SMTP server ready". If I add the line SMTPClient.EnableSsl = true; I get the following error:

"The remote certificate is invalid according to the validation procedure"

What gives?

BrianFoote at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 4

You should use EnableSSL=true.
You say that once you used it you are getting the "The remote certificate is invalid according to the validation procedure". This is because the remote certificate has errors.
You can look at the errors you are getting by hooking up a remote certificate validation call back. You can also enable tracing and see exactly what kind of errors you are getting without having to hook up a call back. Then you can decide how you want to fix this.

I addresses this issue with an example in my blog

http://blogs.msdn.com/dgorti/archive/2005/09/18/471003.aspx

DurgaprasadGorti at 2007-9-9 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified