IT Community - Software Programming, Web Development and Technical Support

How to Send mail using dot net ...?

This is a discussion on How to Send mail using dot net ...? within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi All... How to send HTML mail in ASP.NET? thnks.......


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 01-16-2008, 05:44 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default How to Send mail using dot net ...?

Hi All...

How to send HTML mail in ASP.NET?


thnks....
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-16-2008, 05:48 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: How to Send mail using dot net ...?

Hi Deeban...

You can send mails using smtpclass...

Here is the sample code...

Code:
MailMessage mail = new MailMessage(); 
mail.To = "To Address"; 
mail.From = "From Address"; 
mail.Subject = "Test."; 
mail.BodyFormat = MailFormat.Html; 
mail.Body = "Test Message"; 
SmtpMail.SmtpServer = "localhost"; //your real server goes here 
SmtpMail.Send( mail );
i hope this will help you...
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 01-16-2008, 05:49 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default Re: How to Send mail using dot net ...?

Hi Sathish...

Thanks for your reply... one more doubt! What are the namespaces used to send mails...


thnks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 01-16-2008, 05:50 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: How to Send mail using dot net ...?

Hi Deeban,


Use System.Web.Mail
The System.Web.Mail namespace contains classes that enable you to construct and send messages using the CDOSYS (Collaboration Data Objects for Windows 2000) message component. The mail message is delivered either through the SMTP mail service built into Microsoft Windows 2000 or through an arbitrary SMTP server. The classes in this namespace can be used from ASP.NET or from any managed application.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 01-16-2008, 05:52 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default How do I configure a local SMTP server?

Hi Sathish...

How do I configure a local SMTP server?


thnks...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 01-16-2008, 05:55 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 350
Venkat is on a distinguished road
Default Re: How to Send mail using dot net ...?

hi deeban,

Namespace used in the .NET 2.0 is the System.Net.Mail that will allow you to send an email.

The following is a basic example of sending a message:

//Create a mail message

MailMessage message =

new MailMessage("From Address", "To Address", "Subject",

"Body");


// Create a mail object specifying the address of your SMTP mail server

SmtpClient mail = new SmtpClient("Mail Server Address");

mail.Send(message);

If you take a look at the objects under this namespace (using the Object Explorer tool found under the View menu) you will see that the MailMessage object has properties to specify what format the email should be sent in (Text, HTML) and what priority should be given to the message among other things.

Also, the SmtpClient object has properties that allow you to specify how the message should be sent.

thanks.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 01-16-2008, 05:55 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: How to Send mail using dot net ...?

Hi Deeban...
Code:
Install the SMTP virtual server that is part of IIS. 
·	You will need your Windows installation CD. 
·	Use Add or Remove Programs in the Windows Control Panel to launch Add/Remove Windows Components. 
·	Select Internet Information Services (IIS) and then click Details. 
·	Check SMTP Service and then click OK. 
·	The installation process will prompt you for your Windows CD and will install the SMTP virtual server. 

After installing the SMTP server (also reboot), configure it by following these steps: 
1.	In the Control Panel, choose Administrative Tools, and then choose Internet Information Services. 
2.	Open the node for your computer, right-click the Default SMTP Virtual Server node and choose Properties. 
3.	In the Access tab, click Connection. 
4.	Select Only the list below, click Add and add the IP 127.0.0.1. This restricts connections to just the local computer, i.e., localhost. Close the Connection dialog box. 
5.	Click Relay and repeat Step 5 to allow only localhost to relay through this server. 
In your firewall or router (or both), close incoming port 25. This is an important security measure that will prevent spammers from finding your SMTP server and using it to relay spam.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 01-16-2008, 06:04 AM
a.deeban a.deeban is offline
D-Web Analyst
 
Join Date: May 2007
Posts: 279
a.deeban is on a distinguished road
Default Why do I get the error message "The transport failed to connect to the server "?

Hi...

Why do I get the error message "The transport failed to connect to the server "?


thnx...
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 01-16-2008, 06:07 AM
Sathish Kumar Sathish Kumar is offline
D-Web Analyst
 
Join Date: Feb 2007
Posts: 304
Sathish Kumar is on a distinguished road
Default Re: How to Send mail using dot net ...?

Hi Deeban....


Code:
This is a network related error. Your application cannot connect to the mail server specified.

1. Make sure that the following are true about SmtpMail.SmtpServer:
2. Is a valid SMTP Server 
3. Make sure that the server System.Web.Mail is running or can connect to the mail server. Some times firewalls or proxy servers can get in the way. 
4. Try specifying the value by IP address. Poor DNS resolution can sometimes hinder name lookups. 
5. Make sure that the mail server is running at port 25. 
6. If you did not specify a SmtpMail.SmtpServer property, or if SmtpMail.SmtpServer points to "localhost" (or the equivalent), be sure the SMTP Service is running on port 25. 
7. For testing purposes change the MailMessage.From and MailMessage.To properties to an address that exists on SmtpMail.SmtpServer. Some times this exception is thrown, when it really is a relay issue.
__________________
Sathish Kumar.R
Knowledge is meant to SHARE
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 01-17-2008, 09:20 PM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 138
GDevakii is on a distinguished road
Smile Re: How to Send mail using dot net ...?

using System.Web.Mail;

MailMessage myMessage = new MailMessage();



myMessage.To = this.EmailAddress;
myMessage.From = Environment.UserName + "@knowdotnet.com";
myMessage.Priority = this.MessagePriority;
myMessage.Subject = String.Format("Message from {0} at {1}", this.From, this.Company);
StringBuilder sb = new StringBuilder();
sb.Append(To + ", you received a Message from " + From + " with " + this.Company + "\r\n\r\n");
sb.Append("at " + MessageDate + " " + MessageTime + "\r\n\r\n");
sb.Append("Regarding : " + this.Regarding + "\r\n\r\n");
sb.Append("They : " + this.PhoneActions + "\r\n\r\n");
sb.Append("They can be reached at : " + this.Phone + "\r\n\r\n");
sb.Append("Their Message: " + this.Message + "\r\n\r\n");
sb.Append("Initialed: " + Environment.UserName);
myMessage.Body = sb.ToString();

try
{
SmtpMail.Send(myMessage);
}
catch(System.Exception ex)
{
Debug.Assert(false, ex.ToString());
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to send mail with multiple attachments? poornima ASP and ASP.NET Programming 5 02-01-2008 03:07 AM
How can we send mail using JavaScript? sundarraja PHP Programming 2 01-22-2008 03:57 AM
send the sms using SMS/MMS Gateway in php varghese PHP Programming 1 09-18-2007 08:32 AM
How can we send mail using JavaScript? Sabari HTML, CSS and Javascript Coding Techniques 3 09-12-2007 12:33 AM
How to Send Mail Using Stored Procedure in MS SQL SERVER 200x?? Gopisoft Database Support 1 07-17-2007 09:43 AM


All times are GMT -7. The time now is 07:15 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0