Home | Contact Us | Download | Support | Purchase | Shopping Cart | Products


Product List
  "Great stuff, great support."
Mike
Algarve
 
More
Testimonials

Using aspNetPOP3 from a Non-Visual Studio .NET environment.

Summary

The following steps will demonstrate how to use aspNetPOP3 in a non-Visual Studio .NET environment. For this ASP.NET application to work successfully you will need FTP access or file share access to your website.

Uploading aspNetPOP3 to your ASP.NET application

1. FTP (or through file sharing) connect to your web application.

2. Locate the /Bin directory. If there isn't a directory named Bin you will need to create it under the root directory.

3. Upload the aspNetPOP3.dll to the /Bin directory. By default, the aspNetPOP3.dll can be found in c:\Program Files\advancedintellect\aspNetPOP3. 

Creating a Sample Page

Once the aspNetPOP3 has been uploaded, you will be able to create a test ASP.NET page. The following steps will demonstrate this, using both C# and VB.NET.

1. To create a sample page, called EmailSample.aspx, start Notepad.

2. If you are using C# as your development language, enter the following code. If you are using VB.NET, that code can be found in the next step.

 

[C#]

	
<%@ Page Language="C#" %>
<%@ Import Namespace="aspNetPOP3"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>EmailTest</title>
  </head>
  <body >

    <form id="Form2" method="post" runat="server">
	<table>
		<tr>
			<td>Enter your Server Address</td>
			<td><input type=text id="txtServer" runat=server NAME="txtServer">
<asp:RequiredFieldValidator id=RequiredFieldValidator1 runat="server"
ErrorMessage="Required" ControlToValidate="txtServer"></asp:RequiredFieldValidator> </td> </tr> <tr> <td>Enter your username</td> <td><input type=text id=txtUsername runat=server NAME="txtUsername">
<asp:RequiredFieldValidator id=RequiredFieldValidator2 runat="server"
ErrorMessage="Required" ControlToValidate="txtUsername"></asp:RequiredFieldValidator></td> </tr> <tr> <td>Enter your password</td> <td><input type=password id=txtPassword runat=server NAME="txtPassword">
<asp:RequiredFieldValidator id=RequiredFieldValidator3 runat="server"
ErrorMessage="Required" ControlToValidate="txtPassword"></asp:RequiredFieldValidator></td> </tr> <tr> <td colspan=2 align=middle>
<input type=submit id=cmdSubmit value="Download 1st Message" runat=server
NAME="cmdSubmit" onserverclick="cmdSubmit_ServerClick"></td> </tr> </table> <br> <asp:literal ID=Message1 Runat=server></asp:literal> </form> </body> </html> <script runat="server"> private void cmdSubmit_ServerClick(object sender, System.EventArgs e) { //normally validate username and password. Validation left out for code simplification POP3 pop = new POP3( txtServer.Value, txtUsername.Value, txtPassword.Value ); try { //connect to the server pop.Connect(); } catch( Exception ex ) { //record an exceptions and exit Message1.Text = "<font color=red>The following exception occurred: <br>"
+ ex.Message + "</font>"; return; } int count = pop.MessageCount(); string msg = string.Empty; if( count > 1 ) { //get the first message msg = "<strong>Message 1</strong><br><br>"; msg += "<pre>" + Server.HtmlEncode( pop.GetMessageAsText(1) ) +"</pre>"; } else { //if the first message doesn't exist, write out a friendly message msg = "No messages at the server"; } //disconnect pop.Disconnect(); //show the message Message1.Text = msg; } </script>

 

[VB.NET]

	
<%@ Page Language="vb" %>
<%@ Import Namespace="aspNetPOP3"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>EmailTest</title>
  </head>
  <body >

    <form id="Form2" method="post" runat="server">
	<table>
		<tr>
			<td>Enter your Server Address</td>
			<td><input type=text id="txtServer" runat=server NAME="txtServer">
<asp:RequiredFieldValidator id=RequiredFieldValidator1 runat="server"
ErrorMessage="Required" ControlToValidate="txtServer"></asp:RequiredFieldValidator> </td> </tr> <tr> <td>Enter your username</td> <td><input type=text id=txtUsername runat=server NAME="txtUsername">
<asp:RequiredFieldValidator id=RequiredFieldValidator2 runat="server"
ErrorMessage="Required" ControlToValidate="txtUsername"></asp:RequiredFieldValidator></td> </tr> <tr> <td>Enter your password</td> <td><input type=password id=txtPassword runat=server NAME="txtPassword">
<asp:RequiredFieldValidator id=RequiredFieldValidator3 runat="server"
ErrorMessage="Required" ControlToValidate="txtPassword"></asp:RequiredFieldValidator></td> </tr> <tr> <td colspan=2 align=middle><input type=submit id=cmdSubmit
value="Download 1st Message" runat=server NAME="cmdSubmit"
onserverclick="cmdSubmit_ServerClick"></td> </tr> </table> <br> <asp:literal ID=Message1 Runat=server></asp:literal> </form> </body> </html> <script runat="server"> Private Sub cmdSubmit_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) 'normally validate username and password. Validation left out for code simplification Dim pop As New POP3(txtServer.Value, txtUsername.Value, txtPassword.Value) Try 'connect to the server pop.Connect() Catch ex As Exception 'record an exceptions and exit Message1.Text = "<font color=red>The following exception occurred: <br>" + ex.Message + "</font>" Return End Try Dim count As Integer = pop.MessageCount() Dim msg As String = String.Empty If count > 1 Then 'get the first message msg = "<strong>Message 1</strong><br><br>" msg += "<pre>" + Server.HtmlEncode(pop.GetMessageAsText(1)) + "</pre>" Else 'if the first message doesn't exist, write out a friendly message msg = "No messages at the server" End If 'disconnect pop.Disconnect() 'show the message Message1.Text = msg End Sub </script>

 

4. This code will connect to the POP3 server specified by txtServer, txtUsername, and txtPassword. Once aspNetPOP3 connects to the server, it calls MessageCount() to see if any messages are available. If at least 1 message is available, aspNetPOP3 calls GetMessageAsText(), to retrieve the message, and then HtmlEncodes the message, and sends the content to the Message1 <asp:literal> control.

5. Save this file as EmailSample.aspx and upload it to your web application.
     Note: You will need to change the Server, FromAddress, and To properties to reflect your local mail server and email addresses.

6. Open Internet Explorer (or a suitable web browser) and navigate it to your website and view the EmailSample.aspx (for example http://localhost/EmailSample.aspx).

7. Enter your Mail Server address, username and password. If at least 1 message is available at the POP3 server, it will be downloaded and displayed in the browser.

Summary

That's all there is to using aspNetPOP3 from a Non - Visual Studio .NET environment. In these few simple steps you were able to create an email and send it from an ASP.NET page.

 

 



The box is not shipped. aspNetPOP3 is a downloadable product.