Sending mail message ssl problem  
Author Message

PostPosted: .NET Framework Networking and Communication, Sending mail message ssl problem Top


I got a problem sending mail with ssl in c# .net.
I installed my own mailserver for testing and tryed to send some mail. It all work fine.

When i enable SSL on the mail server and i try to send an e-mail in vs2005 c#, it give me an exception that the mail server does not support secured connections.

So i tryed to send mail in microsoft outlook to my mail server with SSL and this works. So i dont understand the exception since it does support secured connections.

Heres my code in C#

string host = "localhost";
string ;
string to = ;
int port = 25;

MailMessage message = new MailMessage(from, to);
message.Subject =
"SSL Test Message";

SmtpClient client = new SmtpClient(host);
client.EnableSsl =
client.Port = port;

if (!File.Exists("caroot.cer"))
throw new ApplicationException("Can not load certificate");

X509Certificate certificate = new X509Certificate("caroot.cer");

message.Body =
"Mail message send succesfully" + Environment.NewLine + Environment.NewLine +
"from host " + host + Environment.NewLine +
"From port " + port + Environment.NewLine +
"From email " + from + Environment.NewLine +
"To email " + to;

textBox1.Text =
"scanning port: " + client.Port.ToString();


textBox2.Text =
"Mail message send succesfully";
catch (Exception e1)
textBox2.Text = e1.Message.ToString();

Someone has any idea whats wrong
Thnx and Greetings Martin

.NET Development8