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

Summary

The following steps will demonstrate how to use aspNetIMAP 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 aspNetIMAP 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 aspNetIMAP.dll and the aspNetMime20.dll to the /Bin directory. By default the aspNetIMAP.dll and the  aspNetMime20.dll can be found in c:\Program Files\advancedintellect\aspNetIMAP. 

Creating a Sample Page

Once the aspNetIMAP.dll 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 ImapSample.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#] For reference, this code can be found in the following page (ImapSampleCS.aspx.txt)

<%@ Page Language="C#" %>
<%@ Import Namespace="aspNetIMAP"%>
<script runat=server>
private void Page_Load(object sender, System.EventArgs e)
	{
			//set various properties
			IMAP4 imap = new IMAP4( "127.0.0.1" );
			imap.Username = "dave@blah.com";
			imap.Password = "test";

			//create an in memory log for testing purposes
			imap.Logger = new IMAPLog();
			imap.Logger.InMemory = true;

			try{
					imap.Login();

					//list all of the folders
					MailFolderCollection mfc = imap.FolderList();
					
					//convert the folders to a DataSet
					dgInbox.DataSource = mfc.ToDataSet();
					dgInbox.DataBind();
			}
			catch(Exception ex)
			{
				Response.Write( "<pre>" + ex.ToString() + "</pre>" );
			}
			finally
			{
					imap.Disconnect();
			}
			//write out the log
			ImapLog.Text = imap.Logger.ToString();
	}
</script>
<html>
<head>
</head>
<body>
    <form runat="server" ID="Form1">
    <strong>IMAP Folders</strong>
    <asp:datagrid id=dgInbox runat=server autogeneratecolumns=false>
    <columns>
		<asp:boundcolumn datafield="Name" HeaderText="Name" />
		<asp:boundcolumn datafield="Path" HeaderText="Path" />
		<asp:boundcolumn datafield="Attributes" HeaderText="Attributes" />
    </columns>
    </asp:datagrid>
    <br>
    <strong>IMAP Log</strong>
    <pre>
    <asp:literal id=ImapLog runat=server />
    </pre>
    </form>
</body>
</html>

 

[VB.NET] For reference, this code can be found in the following page (ImapSampleVB.aspx.txt)

<%@ Page Language="C#" %>
<%@ Import Namespace="aspNetIMAP"%>
<script runat=server>

Private Sub Page_Load(sender As Object, e As System.EventArgs)
   'set various properties
   Dim imap As New IMAP4("127.0.0.1")
   imap.Username = "dave@blah.com"
   imap.Password = "test"
   
   'create an in memory log for testing purposes
   imap.Logger = New IMAPLog()
   imap.Logger.InMemory = True
   
   Try
      imap.Login()
      
      'list all of the folders
      Dim mfc As MailFolderCollection = imap.FolderList()
      
      'convert the folders to a DataSet
      dgInbox.DataSource = mfc.ToDataSet()
      dgInbox.DataBind()
   Catch ex As Exception
      Response.Write(("<pre>" + ex.ToString() + "</pre>"))
   Finally
      imap.Disconnect()
   End Try
   'write out the log
   ImapLog.Text = imap.Logger.ToString()
End Sub 'Page_Load
            
</script>
<html>
<head>
</head>
<body>
    <form runat="server" ID="Form1">
    <strong>IMAP Folders</strong>
    <asp:datagrid id=dgInbox runat=server autogeneratecolumns=false>
    <columns>
		<asp:boundcolumn datafield="Name" HeaderText="Name" />
		<asp:boundcolumn datafield="Path" HeaderText="Path" />
		<asp:boundcolumn datafield="Attributes" HeaderText="Attributes" />
    </columns>
    </asp:datagrid>
    <br>
    <strong>IMAP Log</strong>
    <pre>
    <asp:literal id=ImapLog runat=server />
    </pre>
    </form>
</body>
</html>

 

4. Save this file as ImapSample.aspx and upload it to your web application.
     Note: You will need to change the Server, Username, and Password properties to reflect your IMAP mail server.

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

6. The listing of mail folders will appear, in a datagrid.

Summary

That's all there is to using aspNetIMAP from a Non - Visual Studio .NET environment. In these few simple steps you were able to access your IMAP server from an ASP.NET page.