473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

System.Net.Mail and SSL

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
1 3257
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Trond A. S. Andersen | last post by:
Hi, all! I'm trying to use the System.Web.Mail. "package" combinded with System.Web.Mail.SmtpMail in order to send MS Excel spreadsheets attached to mail messages. However, sending one single...
3
by: Phil Mc | last post by:
Hi has anyone come accross the problem.... with referance to System.Web.Mail.MailMessage and System.Web.Mail.SmtpMail THIS WORKS FINE mail=new MailMessage(); mail.From =...
5
by: martin | last post by:
Hi, I have created a class that is totally seperate from my web application. However this class is used extensivly by the web application for stuff like data access. I wish to add a function to...
3
by: pmud | last post by:
Hi, I have ab ASP.Net Application in which I need to send e-mail on button click. Even though my C# code for that is correct.I am getting the following error:: I think the following error can be...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
2
by: Ryan | last post by:
Hi, I receive an access denied error (see below) when attempting to send an email with BodyFormat=MailFormat.Html from an asp.net page. Exactly the same code works fine in a console...
1
by: theWizard1 | last post by:
The following sends my email, but the attachment is empty. The attachment should contain the data that is in the string that was created from the xmlReader. I have a stored procedure written...
2
by: clevrmnkey | last post by:
I've had nothing but trouble from the System.Net.Mail objects, but I finally need to make them work, and I can't for the life of me see what I'm doing wrong. I pared back my mail transaction to...
10
by: Frank | last post by:
Hi, I am hoping to find out the differences between the System.Net.Mail and System.Web.Mail. Can some nice folks post the differences; or some urls which show the differences? Great Thanks...
2
by: satnamsarai | last post by:
Using System.Net.Mail: Sometimes I get error 'failure sending mail. Unable to write data to the transport connection: An existing connection was forcibly closed by the remote host.' Not sure how...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.