Summary

The following article will describe how to use aspNetIMAP from Visual Studio .NET using VB.NET. This brief tutorial assumes you have IIS installed locally on your machine, and have downloaded and installed aspNetIMAP from www.aspNetIMAP.com . For other examples, be sure to visit www.aspNetIMAP.com/examples.aspx 

 

Instructions

Using Visual Studio .NET (VS.NET ) We will create a single webform (imaptest.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 Basic Projects. Under Templates, select ASP.NET Web Application. In the Location textbox, enter http://localhost/aspNetIMAPTestVB

 

Setting the Reference to aspNetIMAP.

There are two ways to set a reference in VS.NET . Because aspNetIMAP is installed in the GAC (Global Assembly Cache) you can set a reference to the GAC copy, or you can upload the aspNetIMAP.dll and the aspNetMime20.dll to the project and set a reference to the uploaded copies. 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.aspNetIMAP.com/licen.aspx  for more information.)

1. In the Solution Explorer, right-click the project name, aspNetIMAPTest, 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 aspNetIMAP install directory. By default, this directory is C:\Program Files\AdvancedIntellect\aspNetIMAP. Select the aspNetIMAP.dll and the aspNetMime20.dll The Add Existing Item dialog box closes, and the two dlls were uploaded to the root directory of your project.

3. In the Solution Explorer, right-click the project name aspNetIMAPTestVB and select Add Reference. The Add Reference dialog box appears. Click the Browse button. The Select Component dialog box appears. Select the aspNetIMAP.dll and aspNetMime20.dll files. The Select Component dialog box closes. Click OK. The Add Reference dialog box closes, and a reference is set to aspNetIMAP and aspNetMime.

 

Create a Test Page.

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

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

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

3. At the top of the page, add the following Imports statement.

	 Imports aspNetIMAP

4. Under the Page_Load function, replace the line

	 'Put user code to initialize the page here

 

So the entire Page_Load method is as follows:

 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        '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

        Dim dgInbox As New DataGrid()
        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
        Dim ImapLog As New Literal()
        ImapLog.Text = "IMAP Log<pre>" + imap.Logger.ToString() + "</pre>"


        'add the datagrid and the log to the page
        Page.Controls.Add(dgInbox)
        Page.Controls.Add(ImapLog)
    End Sub

 

 

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

        Dim imap As New IMAP4("127.0.0.1")
        imap.Username = "dave@blah.com"
        imap.Password = "test"
 

 

Testing The Page

Lets compile and test the page.

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

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

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

 

Summary

That's all there is to using aspNetIMAP from Visual Studio .NET. In these few simple steps you were able to create a project, set a reference to aspNetIMAP, and download a list of folders. For more questions or comments, feel free to write support@advancedIntellect.com