C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » Email »

Sending email through C#


Posted Date: 09 Jan 2009    Resource Type: Code Snippets    Category: Email
Author: ShashiMember Level: Gold    
Rating: 1 out of 5Points: 10



sending email through C#:
Let’s see the code to send an email. This code is executed on the button click control. First of all don't forget to add the
using System.Web.Mail;
namespace which provides the methods and properties for sending an email.


private void Button1_Click(object sender, System.EventArgs e)
{
MailMessage mail = new MailMessage();
mail.To = txtTo.Text; //put the TO ADDRESS here.
mail.From = txtFrom.Text; //put the FROM ADDRESS here.
mail.Subject = txtSubject.Text; //put the SUBJECT here.
mail.Body = txtBody.Text; //put the BODY here.
SmtpMail.SmtpServer = "localhost"; //put SMTP SERVER you will use here.
SmtpMail.Send(mail);
}


Description of the above Code:
The code you see above is very simple to understand. In the button click event we made the object/instance of the MailMessage class. MailMessage is responsible for sending emails. It also provides several properties and methods. Later we assigned several properties.

The line SmtpMail.SmtpServer = "localhost" sets the server for the mail. If you are running the application on your own PC using IIS than your server will be "localhost". If your website is running on the production server you can have different SmtpServer name.

The final line SmtpMail.Send(mail) sends the email to the email address provided.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Sending email  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Send Email using ASP.NET 2.0 and C#
Previous Resource: Sending Mail to Multiple recipients with attachement or as Inline Image
Return to Discussion Resource Index
Post New Resource
Category: Email


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use