473,699 Members | 2,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot smtp in C# - cant connect to server

I am trying to send email in C#. I wrote 2 pieces of code:
1.
MailMessage mail = new MailMessage();
mail.From = "from_addre ss";
mail.To = "to_address ";
mail.Subject = "subject";
mail.BodyFormat = MailFormat.Text ;
mail.Body = "body";
SmtpMail.SmtpSe rver = "smtp.serve r";
mail.Fields.Cle ar();
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e", "1");
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername", "userl");
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword", "password") ;
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpserverport" , "25");
SmtpMail.Send(m ail);

/////////////////////////////////////////////////////////////////////////////////////////////
2.

MailMessage mail = new MailMessage("fr om_address", "to_address l");
mail.Subject = "subject";
mail.Body = "body";
SmtpClient smtp = new SmtpClient("smt p.server", 25);
smtp.EnableSsl = false;
smtp.Credential s = new System.Net.Netw orkCredential(" user", "password") ;
smtp.Send(mail) ;
I am thrown error:

System.Net.Mail .SmtpException: Failure sending mail. --->
System.Net.WebE xception: Unable to connect to the remote server --->
System.Net.Sock ets.SocketExcep tion: A connection attempt failed because the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond
what is wrong.?

PS
I wrote another application (in borland c++) where I specified the same data
(from/to addresse, server address, user/password) and it works ok
Sep 27 '06 #1
5 23756
Try adding the '@' character before your quoted strings:

i.e.

mail.Fileds.Add (@"http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e","1");

The compiler may be interpreting everything after // as a comment.

"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:B1******** *************** ***********@mic rosoft.com...
>I am trying to send email in C#. I wrote 2 pieces of code:
1.
MailMessage mail = new MailMessage();
mail.From = "from_addre ss";
mail.To = "to_address ";
mail.Subject = "subject";
mail.BodyFormat = MailFormat.Text ;
mail.Body = "body";
SmtpMail.SmtpSe rver = "smtp.serve r";
mail.Fields.Cle ar();
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e",
"1");
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername",
"userl");
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword",
"password") ;
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpserverport" ,
"25");
SmtpMail.Send(m ail);

/////////////////////////////////////////////////////////////////////////////////////////////
2.

MailMessage mail = new MailMessage("fr om_address", "to_address l");
mail.Subject = "subject";
mail.Body = "body";
SmtpClient smtp = new SmtpClient("smt p.server", 25);
smtp.EnableSsl = false;
smtp.Credential s = new System.Net.Netw orkCredential(" user", "password") ;
smtp.Send(mail) ;
I am thrown error:

System.Net.Mail .SmtpException: Failure sending mail. --->
System.Net.WebE xception: Unable to connect to the remote server --->
System.Net.Sock ets.SocketExcep tion: A connection attempt failed because
the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond
what is wrong.?

PS
I wrote another application (in borland c++) where I specified the same
data
(from/to addresse, server address, user/password) and it works ok

Sep 27 '06 #2
You need to make sure your smtp server is reachable, that is try to connect
to it using something simple like "ping" or "telnet smtp.server 25".
Firewall may block this port as well, so watch out for them.

Willy.
"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:B1******** *************** ***********@mic rosoft.com...
|I am trying to send email in C#. I wrote 2 pieces of code:
| 1.
| MailMessage mail = new MailMessage();
| mail.From = "from_addre ss";
| mail.To = "to_address ";
| mail.Subject = "subject";
| mail.BodyFormat = MailFormat.Text ;
| mail.Body = "body";
| SmtpMail.SmtpSe rver = "smtp.serve r";
| mail.Fields.Cle ar();
|
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e",
"1");
|
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername",
"userl");
|
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword",
"password") ;
|
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpserverport" ,
"25");
| SmtpMail.Send(m ail);
|
|
/////////////////////////////////////////////////////////////////////////////////////////////
| 2.
|
| MailMessage mail = new MailMessage("fr om_address", "to_address l");
| mail.Subject = "subject";
| mail.Body = "body";
| SmtpClient smtp = new SmtpClient("smt p.server", 25);
| smtp.EnableSsl = false;
| smtp.Credential s = new System.Net.Netw orkCredential(" user", "password") ;
| smtp.Send(mail) ;
|
|
| I am thrown error:
|
| System.Net.Mail .SmtpException: Failure sending mail. --->
| System.Net.WebE xception: Unable to connect to the remote server --->
| System.Net.Sock ets.SocketExcep tion: A connection attempt failed because
the
| connected party did not properly respond after a period of time, or
| established connection failed because connected host has failed to respond
|
|
| what is wrong.?
|
| PS
| I wrote another application (in borland c++) where I specified the same
data
| (from/to addresse, server address, user/password) and it works ok
Sep 27 '06 #3
Jim Boddie wrote:
Try adding the '@' character before your quoted strings:

i.e.
mail.Fileds.Add (@"http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e","1");

The compiler may be interpreting everything after // as a comment.
No - otherwise the line wouldn't compile in the first place.

Forward slashes are fine in string literals. Verbatim string literals
(i.e. those with the @ in front) deal with escaping which is normally
done with backslashes.

Jon

Sep 27 '06 #4

"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:B1******** *************** ***********@mic rosoft.com...
>I am trying to send email in C#. I wrote 2 pieces of code:
1.
MailMessage mail = new MailMessage();
mail.From = "from_addre ss";
mail.To = "to_address ";
mail.Subject = "subject";
mail.BodyFormat = MailFormat.Text ;
mail.Body = "body";
SmtpMail.SmtpSe rver = "smtp.serve r";
mail.Fields.Cle ar();
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpauthenticat e",
"1");
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername",
"userl");
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword",
"password") ;
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpserverport" ,
"25");
SmtpMail.Send(m ail);

/////////////////////////////////////////////////////////////////////////////////////////////
2.

MailMessage mail = new MailMessage("fr om_address", "to_address l");
mail.Subject = "subject";
mail.Body = "body";
SmtpClient smtp = new SmtpClient("smt p.server", 25);
smtp.EnableSsl = false;
smtp.Credential s = new System.Net.Netw orkCredential(" user", "password") ;
smtp.Send(mail) ;
I am thrown error:

System.Net.Mail .SmtpException: Failure sending mail. --->
System.Net.WebE xception: Unable to connect to the remote server --->
System.Net.Sock ets.SocketExcep tion: A connection attempt failed because
the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond
what is wrong.?

PS
I wrote another application (in borland c++) where I specified the same
data
(from/to addresse, server address, user/password) and it works ok
I'd double check you can telnet into it on port 25 as someone else said -
I've used code similar to your version 2 and it works ok...
Sep 27 '06 #5
Chris,

Those schema.microsof t.com things are tricky.

You also need to be aware of the different authentication schemes.

None
Basic
SSL

I have complete downloadable examples (1.1 and 2.0) at:

http://sholliday.spaces.live.com/?_c...26ayear%3d2006

2/8/2006 datestamp


"Chris" <Ch***@discussi ons.microsoft.c omwrote in message
news:B1******** *************** ***********@mic rosoft.com...
I am trying to send email in C#. I wrote 2 pieces of code:
1.
MailMessage mail = new MailMessage();
mail.From = "from_addre ss";
mail.To = "to_address ";
mail.Subject = "subject";
mail.BodyFormat = MailFormat.Text ;
mail.Body = "body";
SmtpMail.SmtpSe rver = "smtp.serve r";
mail.Fields.Cle ar();
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpauthenti
cate", "1");
>
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendusername
", "userl");
>
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/sendpassword
", "password") ;
>
mail.Fields.Add ("http://schemas.microso ft.com/cdo/configuration/smtpserverpo
rt", "25");
SmtpMail.Send(m ail);

////////////////////////////////////////////////////////////////////////////
/////////////////
2.

MailMessage mail = new MailMessage("fr om_address", "to_address l");
mail.Subject = "subject";
mail.Body = "body";
SmtpClient smtp = new SmtpClient("smt p.server", 25);
smtp.EnableSsl = false;
smtp.Credential s = new System.Net.Netw orkCredential(" user", "password") ;
smtp.Send(mail) ;
I am thrown error:

System.Net.Mail .SmtpException: Failure sending mail. --->
System.Net.WebE xception: Unable to connect to the remote server --->
System.Net.Sock ets.SocketExcep tion: A connection attempt failed because
the
connected party did not properly respond after a period of time, or
established connection failed because connected host has failed to respond
what is wrong.?

PS
I wrote another application (in borland c++) where I specified the same
data
(from/to addresse, server address, user/password) and it works ok

Sep 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1627
by: aa | last post by:
Since recently opening a php file on my w2k Pro takes ages and often ends up with an error massege "cannot conect to fastcgi server". However if I refresh the page it starts working normally. How do I fix it?
0
3454
by: Amol Shambharkar | last post by:
Hello Everyone, I am hoping someone could help me out with this.I am using Visual Studio .NET 2003 to create a web application on a remote IIS 5.0 server using the File Share web access method.The problem is I get the following two errors everytime I try to create the application: Error 1: The web was created successfully, but an error occured trying to configure the application root of this web.Web projects may not operate correctly...
6
1974
by: tony010409020622 | last post by:
My WebForm1.aspx works fine when I connect via localhost, AND when I connect using the IP address. HOWEVER, NO ONE ELSE can connect using my IP address. Capitalization is correct, Firewall is off, and still everyone just times out. Help is greatly appreciated, 'specially since I've been working on this site for over 24 hours straight :-| Thanks
4
1762
by: Emilio | last post by:
Question about Shared Sub Connect(server As , message As ) Why is in square brackets? Is it like Shared Sub Connect(server() As String, message() As String)
4
1320
by: Chris L | last post by:
Hi there, I'm running VS.NET 2003 on XP Home, so I have Web Matrix installed as a web server. I wanted to create my first web application with VS.NET, but when I select New Project -> asp.net web application I get the following message: VS.NET cannot detect a web server running asp.net 1.1... etc. I have the ..NET framework installed (SDK).
2
3591
by: yodboy | last post by:
hi there Im going nuts - any help appreciated trying to connect to access db over a network so far - I can connect to the db using the same odbc with excel I can connect to a copy of the db using a similar odbc on a local drive with php
3
1251
by: suhailkhalil | last post by:
I'm using javascirpt calendar control and using the below statement to populate date in textbox txtDate. I'm using master page in VS2005. javascript:show_calendar('document.GetElementById("<%=txtDate.ClientID%>")'); but this gives the parser error <%... %> tag cannot be used at server side I've tried <%# also but to no avail. Any help is hugely appreciated
2
9789
by: jeffhan | last post by:
we have os/400 db2 database at the backend. i installed db2 v9 connect server on one windows server which is locating the same network with database server. now how to i configure the connect server and client, so client could access the database through the connect server? like that: db2client <--db2 connect server <--db2 mainframe database
6
10442
by: Jean-Marc Blaise | last post by:
Hi, I have installed DB2 9.5 directly from FP1 on Windows in custom mode with COMP=CONNECT_SUPPORT. I then added my DB2 Server license. I am surprise that db2licm refers to a DB2 Connect Server. Is there a way to remove the product I have never installed ? db2licm -l Product name: "DB2 Enterprise Server Edition"
0
8706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9199
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...
1
8947
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
8902
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
7787
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...
0
5891
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
4642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3076
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2366
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.