By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

System.Net.Mail and SSL

P: n/a
Hi all
I am having trouble with sending email via a C#2.0 application, I use
the same settings as I use in Outlook but I cannot get email to send.

I am trying to use SSL on port 465 and get the error below, If I disable
SSL and use port 587 all goes well.
I have been Googling for 2 days without success and this seems to be a
common problem.
Any help is appreciated.

Thanks.
Here is the code I am using.
MailMessage message = new MailMessage();
message.From = new MailAddress("my*******@mydomain.com");
message.Sender = new MailAddress("my*******@mydomain.com");
message.To.Add(new MailAddress("my*******@mydomain.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";

SmtpClient smtpClient = new SmtpClient("smtp.bizmail.yahoo.com", 465);
System.Net.NetworkCredential mc = new
System.Net.NetworkCredential("my********@mydomain. com", "mypassword");

smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = mc ;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network ;
smtpClient.EnableSsl = true;

try{
smtpClient.Send(message);

}
catch(Exception e) {
System.Console.WriteLine(e.InnerException.ToString ());
}

smtpClient = null;

Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);

The error I get is this:

Unable to read data from the transport connection: An existing
connection was forcibly closed by the remote host.

at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32
offset, Int32 size)
at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(S mtpReplyReader
caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(Sm tpReplyReader
caller)
at System.Net.Mail.SmtpReplyReader.ReadLine()
at System.Net.Mail.SmtpConnection.GetConnection(Strin g host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
Nov 22 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Nov 22, 7:51 pm, WIzmanG <notha...@microsft.comwrote:
Hi all
I am having trouble with sending email via a C#2.0 application, I use
the same settings as I use in Outlook but I cannot get email to send.

I am trying to use SSL on port 465 and get the error below, If I disable
SSL and use port 587 all goes well.

I have been Googling for 2 days without success and this seems to be a
common problem.

Any help is appreciated.

Thanks.

Here is the code I am using.

MailMessage message = new MailMessage();
message.From = new MailAddress("myaddr...@mydomain.com");
message.Sender = new MailAddress("myaddr...@mydomain.com");
message.To.Add(new MailAddress("myaddr...@mydomain.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";

SmtpClient smtpClient = new SmtpClient("smtp.bizmail.yahoo.com", 465);
System.Net.NetworkCredential mc = new
System.Net.NetworkCredential("myusern...@mydomain. com", "mypassword");

smtpClient.UseDefaultCredentials = false;
smtpClient.Credentials = mc ;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network ;
smtpClient.EnableSsl = true;

try{
smtpClient.Send(message);

}

catch(Exception e) {
System.Console.WriteLine(e.InnerException.ToString ());

}

smtpClient = null;

Console.Write("Press any key to continue . . . ");
Console.ReadKey(true);

The error I get is this:

Unable to read data from the transport connection: An existing
connection was forcibly closed by the remote host.

at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32
offset, Int32 size)
at System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(S mtpReplyReader
caller, Boolean oneLine)
at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(Sm tpReplyReader
caller)
at System.Net.Mail.SmtpReplyReader.ReadLine()
at System.Net.Mail.SmtpConnection.GetConnection(Strin g host, Int32 port)
at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
from this distance it looks like firewalll problem, are your outlook
and c# code running on same machine ?
are your certiifcates valid ? i had similar problems using IE (instead
of outlook) the problem was certificate and nothing else, if you need
more infos mail me directly instead of newsgroup

kazazic-at-gXmXaXil.com and remove all X

regards
Nov 25 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.