Summary

The following article will describe how to use aspNetEmail from Visual Studio .NET using C#. This brief tutorial assumes you have IIS installed locally on your machine, and have downloaded and installed aspNetEmail from www.aspNetEmail.com . For an updated version of this article, visit www.aspNetEmail.com/examples.aspx 

 

Instructions

Using Visual Studio .NET (VS.NET ) We will create a single webform (emailtest.aspx) and send out an email.

 

1. Launch Visual Studio .NET

2. From the main menu, select the File | New | Project command.

3. The New Project dialog box appears. Under Project Types, Select Visual C# Projects. Under Templates, select ASP.NET Web Application. In the Location textbox, enter http://localhost/aspNetEmailTest

 

Setting the Reference to aspNetEmail.

There are two ways to set a reference in VS.NET . Because aspNetEmail is installed in the GAC (Global Assembly Cache) you can set a reference to the GAC copy, or you can upload the aspNetEmail.dll to the project and set a reference to the uploaded copy. We will upload a copy, and set a reference to the uploaded copy. This method will promote XCOPY deployment. (A comment about licensing: Please be sure you are compliant with your licenses. Check http://www.aspNetEmail.com/licen.aspx  for more information.)

1. In the Solution Explorer, right-click the project name, aspNetEmailTest, and select the Add | Add Existing Item command.

2. The Add Existing Item dialog box appears. Under Files of Type, select All Files(*.*). Navigate to the aspNetEmail install directory. By default, this directory is C:\Program Files\AdvancedIntellect\aspNetEmail. Double-click the aspNetEmail.dll. The Add Existing Item dialog box closes, and the aspNetEmail.dll was uploaded to the root directory of your project.

3. In the Solution Explorer, right-click the project name aspNetEmailTest and select Add Reference. The Add Reference dialog box appears. Click the Browse button. The Select Component dialog box appears. Double-click the aspNetEmail.dll file. The Select Component dialog box closes. Click OK. The Add Reference dialog box closes, and a reference is set to aspNetEmail.

 

Create a Test Page.

Now that we have a reference set, let's create a test page to check aspNetEmail.

1. In the Solution Explorer, right-click the project name aspNetEmailTest, and select Add | Add Webform. The Add New Item dialog box appears. In the Name textbox, enter, emailtest.aspx.

2. In the Solution Explorer, right-click emailtest.aspx, and select View Code.

3. Under the Page_Load function, replace the line

	// Put user code to initialize the page here 

 

With the following code.

 

	aspNetEmail.EmailMessage msg = new aspNetEmail.EmailMessage(); 
	msg.Server = "Mail.mycompany.com"; 
	msg.FromAddress =  me@mycompany.com; 
	msg.To = You@yourcompany.com;
	msg.Subject = 	"Test Email"; 
	msg.Body ="This is a test email."; 
	if ( msg.Send() ) 
	{ 
		Response.Write( "Message Sent."); 
	} 
	else 
	{ 
		Response.Write ("The following error occurred: " + msg.LastException().Message); 
	} 

 

 

You will need to replace the following properties with values that will work with your system:

msg.Server = "Mail.mycompany.com";

msg.FromAddress = me@mycompany.com;

msg.To = You@yourcompany.com;

 

Testing The Page

Lets compile and test the page.

1. In the Solution Explorer, right-click the project name, aspNetEmailTest, and select Build. The project will be compiled.

2. In the Solution Explorer, right-click emailtest.aspx and select View in Browser.

3. Check your email to verify the email was sent to the 'To' address found on the line of code: msg.To = You@yourcompany.com;

 

Summary

That's all there is to using aspNetEmail from Visual Studio .NET. In these few simple steps you were able to create a project, set a reference to aspNetEmail, and send a sample email. For more questions or comments, feel free to write support@aspNetEmail.com