473,910 Members | 5,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 *******@mydomai n.com");
message.Sender = new MailAddress("my *******@mydomai n.com");
message.To.Add( new MailAddress("my *******@mydomai n.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";

SmtpClient smtpClient = new SmtpClient("smt p.bizmail.yahoo .com", 465);
System.Net.Netw orkCredential mc = new
System.Net.Netw orkCredential(" my********@mydo main.com", "mypassword ");

smtpClient.UseD efaultCredentia ls = false;
smtpClient.Cred entials = mc ;
smtpClient.Deli veryMethod = SmtpDeliveryMet hod.Network ;
smtpClient.Enab leSsl = true;

try{
smtpClient.Send (message);

}
catch(Exception e) {
System.Console. WriteLine(e.Inn erException.ToS tring());
}

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.Sock ets.NetworkStre am.Read(Byte[] buffer, Int32
offset, Int32 size)
at System.Net.Dele gatedStream.Rea d(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.Buff eredReadStream. Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.Mail .SmtpReplyReade rFactory.ReadLi nes(SmtpReplyRe ader
caller, Boolean oneLine)
at System.Net.Mail .SmtpReplyReade rFactory.ReadLi ne(SmtpReplyRea der
caller)
at System.Net.Mail .SmtpReplyReade r.ReadLine()
at System.Net.Mail .SmtpConnection .GetConnection( String host, Int32 port)
at System.Net.Mail .SmtpTransport. GetConnection(S tring host, Int32 port)
at System.Net.Mail .SmtpClient.Get Connection()
at System.Net.Mail .SmtpClient.Sen d(MailMessage message)
Nov 22 '07 #1
1 3287
On Nov 22, 7:51 pm, WIzmanG <notha...@micro sft.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("my addr...@mydomai n.com");
message.Sender = new MailAddress("my addr...@mydomai n.com");
message.To.Add( new MailAddress("my addr...@mydomai n.com"));
message.Subject = "This is my subject";
message.Body = "This is the content";

SmtpClient smtpClient = new SmtpClient("smt p.bizmail.yahoo .com", 465);
System.Net.Netw orkCredential mc = new
System.Net.Netw orkCredential(" myusern...@mydo main.com", "mypassword ");

smtpClient.UseD efaultCredentia ls = false;
smtpClient.Cred entials = mc ;
smtpClient.Deli veryMethod = SmtpDeliveryMet hod.Network ;
smtpClient.Enab leSsl = true;

try{
smtpClient.Send (message);

}

catch(Exception e) {
System.Console. WriteLine(e.Inn erException.ToS tring());

}

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.Sock ets.NetworkStre am.Read(Byte[] buffer, Int32
offset, Int32 size)
at System.Net.Dele gatedStream.Rea d(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.Buff eredReadStream. Read(Byte[] buffer, Int32 offset,
Int32 count)
at System.Net.Mail .SmtpReplyReade rFactory.ReadLi nes(SmtpReplyRe ader
caller, Boolean oneLine)
at System.Net.Mail .SmtpReplyReade rFactory.ReadLi ne(SmtpReplyRea der
caller)
at System.Net.Mail .SmtpReplyReade r.ReadLine()
at System.Net.Mail .SmtpConnection .GetConnection( String host, Int32 port)
at System.Net.Mail .SmtpTransport. GetConnection(S tring host, Int32 port)
at System.Net.Mail .SmtpClient.Get Connection()
at System.Net.Mail .SmtpClient.Sen d(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
8694
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 spreadsheet attachment per message, seems to be causing som kind of corruption of the attachment, while several spreadsheets per works just fine. Consider the following three snippets of C# code:
3
3285
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 = "W-MyPcName.mycompany.com"; mail.To=strTo; mail.Cc=strCC; mail.Bcc=strBCC;
5
2242
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 this class that will send email, however my class will not seem to recognise the system.web.mail.mailmessage. my first impression on this is that I may have to use some sort of third
3
4363
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 bcoz of the SMTP virtual server. I cant view the SMTP virtual server in IIS. How to correct this error??? Send failure: System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException:...
1
8193
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 the members of my organization. I think my problem is incorrectly setting the settings on my server or an authentication problem. Here is the code I have written to send a test message: -----Code Begins: Sensitive Information Replaced by -----...
2
3507
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 application, and also succeeds from the asp.net page with BodyFormat=MailFormat.Text. I've recently upgraded from W2K SP4 to WinXP SP2 and am using .Net Framework v1.1 SP1. The code worked fine under W2K SP4.
1
5917
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 using For XML explicit, and it returns an xml reader. Then the following: xmlRdr.MoveToContent(); string myTemp = xmlRdr.ReadOuterXml();
2
17506
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 the bare minimum: System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("<my mail server IP>", 25); smtp.Send("<one of my email addresses>", "<another of my email addresses>", "Hello", "World");
10
3969
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 Frank
2
6836
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 to fix this error. I am able to send messages sometimes both other times randomly following error appear EXCEPTION:
0
11349
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10921
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
11055
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10541
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9727
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8099
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7250
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5939
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4337
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.