Monday, September 8, 2008

Send mail through .aspx C#

By benjarras

How to send an email in Dot Net
All the Contact Us forms needs an e-mail system
In this article you will learn how to send emails from you .aspx site, using plain format, html format also add attachments by two ways, the quick (easy way) and the profesional ( i like this way ) The first step is be sure that the SMTP Server is locally installed at SMTP Service of the IIS

Easy Way
This is an easy and quick way to do that, we will call this form ContactMe.aspx First, we have to import the System.Web.Mail Then in the code behind add the namespace

using System.Web.Mail;
Now build your message

string To = "";
string From = "";
string Subject = "The Famous";
string Body = "Hello World";


What is the SmtpMail?
this class has a method called Send that allows the user to send an email, in this way we set four parameters:

SmtpMail.Send("","","The Famous","Hello World");

As you can see this is the easy and quick way to do that. Now you will lear how to do the professional way (interesting). Here you will send an email including an attachment and CC, we can use the same parameters above

Professional Way (I like this Way)
We have to create an object (MailMessage) called myMail


ASP.Net Feeds