473,473 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

send mail in asp.net(C#)2008

10 New Member
Hello,
This is venkat,
I was trying to send the email using the following codes but error occurs everytime can you fix this.
Expand|Select|Wrap|Line Numbers
  1. using System.Data;
  2. using System.Linq;
  3. using System.Web;
  4. using System.Web.Security;
  5. using System.Web.UI;
  6. using System.Web.UI.HtmlControls;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Xml.Linq;
  10. using System.Net.Mail;
  11.  
  12.     MailMessage mail = new MailMessage();
  13.         mail.To = ToTextBox.Text;
  14.         mail.From=FromTextBox.Text;
  15.         mail.CC=CcTextBox.Text;
  16.         mail.Subject=SubTextBox.Text;
  17.         mail.Body=MsgTextBox.Text;
  18.         System.Net.Mail.SmtpClient SmtpServer = "localhost";
  19.         SmtpServer.Send(mail);
  20.  
is this correct format? pls send if any correct coding for that? also what are the things should declare in the top?
Apr 2 '08 #1
4 1476
GayathriP
17 New Member
The Port No is not specified to send the email.
It can be done by

SmtpServer.Port = <PortNo>;
Apr 3 '08 #2
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
System.Net.Mail.SmtpClient SmtpServer = "localhost";

since you are creating a SmtpClient object you have to create a new one

i.e.
System.Net.Mail.SmtpClient SmtpServer = new System.Net.Mail.SmtpClient("192.168.0.1");
its better to send an ip address to it.
i havent tested it using localhost. (im not sure of that), and yes you may also have to specify the port if it is not on the default smtp port which i thing is 25
Apr 3 '08 #3
pskvenkat
10 New Member
System.Net.Mail.SmtpClient SmtpServer = "localhost";

since you are creating a SmtpClient object you have to create a new one

i.e.
System.Net.Mail.SmtpClient SmtpServer = new System.Net.Mail.SmtpClient("192.168.0.1");
its better to send an ip address to it.
i havent tested it using localhost. (im not sure of that), and yes you may also have to specify the port if it is not on the default smtp port which i thing is 25

Can you tel how can i find the smtp server port number?
Apr 3 '08 #4
Plater
7,872 Recognized Expert Expert
Can you tel how can i find the smtp server port number?
It probably is 25. The real problem was your incorrect "constructor" calling of the SmtpClient class
Apr 3 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Ken Fine | last post by:
I am using VS.NET 2008 and like it a lot. One of the very few things I don't like is a bug that seems to spawn literally thousands of   strings, one after the other, on design view changes....
4
by: bj7lewis | last post by:
I am currently C++/Win32/MFC & C# programmer using VS.NET 2002 and jumped into VS.NET 2003 but that was a waste so I skipped VS.NET 2005 cause buying VS.NET 2003. Now after checking out VS.NET 2008...
4
by: =?Utf-8?B?dGhlamFtaWU=?= | last post by:
Can NET 2008 run side by side with NET 2005? -- Regards, Jamie
1
by: kunalvumca200519 | last post by:
I would like to know about wcx, wpx, wax in vb.net 2008 and what is XAML? Please reply me...
11
by: =?Utf-8?B?QXNhZg==?= | last post by:
Hello, I have just installed VISTA Enterprise and VS.NET 2008. When pressing F5 to debug my test ASP.NET website, IE 7 display the message "Internet Explorer cannot display the webpage". The...
2
by: 14All2C | last post by:
Experts I've heard that its supposed to be easy to use VB.Net objects directly with JavaScript using ASP.Net and Ajax in Visual Studio 2008. I can't find any info anywhere on how to do this,...
3
by: Cirene | last post by:
It seems like the VS.net 2008 editor is slow and buggy. Have you found this to be the case? A few times I am working and all of a sudden all my images are stretched funny. I find out that...
4
by: Ken Fine | last post by:
I've been living with a frustrating issue with VS.NET for some months now and I need to figure out what the problem is. Hopefully someone has run into the same issue and can suggest a fix. I...
2
by: JDeats | last post by:
I apologize if this question is answered on MSDN, I searched and could not find a clear answer: I have a Windows XP PC that has VS.NET 2005 Professional installed. So far my VS.NET 2008...
1
progdoctor
by: progdoctor | last post by:
Guyz... can u tell me the advantage of asp.net 2008 cuz we want to migrate from asp.net 2005 to 2008.In 2005 we use infragistics as controls component. Do visual studio 2008 have components like...
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,...
1
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...
0
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...
1
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.