Reading Emails in Outlook inbox folders

I am developing an application where one of the features my users require is to be able to select emails they have received in Outlook and save them to a SQL database.

How can i present to my users in my .net application a list of their inboxes and emails they have received in Outlook, so they can chose which emails to be passed onto the database? I am using Exchange Server 2003 and vb.net 2005.

I have been able to send emails using the aspose.network.mail through my exchange server, but not anything else.

Regards

Justin

Hello Justin,

Thank you for considering Aspose.Network!

There is an alpha version of Aspose.Network.Data.OutlookClient could fulfill your requirement, which is read from and parse Outlook’s folders content. I will upload the dll and demo project here, please try it out. Here are some sample codes:

using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Aspose.Network.Data.OutlookClient;
namespace example
{
class Program
{
static void Main(string[] args)
{
// ADO.NET style interface
Aspose.Network.Data.OutlookClient.OutlookConnection connection;
Aspose.Network.Data.OutlookClient.OutlookCommand cmd;
Aspose.Network.Data.OutlookClient.OutlookDataAdapter adapter;

connection = new OutlookConnection();
cmd = new OutlookCommand();
adapter = new OutlookDataAdapter();

ArrayList connectionList = connection.GetConnectionList();
Console.WriteLine("Available connections to outlook:");
for (int i = 0; i < connectionList.Count; i++)
{
Console.WriteLine(connectionList.ToString());
}
//
// choose the first connection here, which is "personal folders" in my outlook
//
connection.ConnectionString = connectionList[0].ToString();
cmd.Connection = connection;
adapter.SelectCommand = cmd;

Outlook.Folders folders = cmd.GetFolders();
Console.WriteLine("Available folders:");

//starts from 1
for (int i = 1; i < folders.Count; i++)
{
Console.WriteLine(folders.Item(i).Name);
}
//
// the second folder of my outlook personal folder is Inbox
// so I choose folders.Item(2), other folders are the same syntax as below
//
cmd.CommandText = "SELECT * FROM " + folders.Item(2).Name;
//
// now the CommandText is "SELECT * FROM Inbox" when I run it
//
System.Data.DataSet result = new System.Data.DataSet();
adapter.Fill(result);

// print out messages
for (int i = 0; i < result.Tables[0].Rows.Count; i++)
{
Console.Write("\n ================= \n");
for (int j = 0; j < result.Tables[ 0 ].Columns.Count; j++)
{
Console.WriteLine(result.Tables[ 0 ].Rows[ i ][ j ].ToString( ));
}
}
}
}
}

In the sample above, the return result is a DataSet, which is very handy when you are writing winform programs. Here use Console.WriteLine just for simplicity.

When you run this demo, the following message may popup:
[http://www.aspose.com/products/Aspose.Network/tmp/Outlook1.jpg ](https://forum.aspose.com/products/Aspose.Network/tmp/Outlook1.jpg)
That is outlook’s warning: other program is reading its folders.

The demo project could be downloaded here:
[http://www.aspose.com/products/Aspose.Network/tmp/Outlook.Demo.zip ](https://forum.aspose.com/products/Aspose.Network/tmp/Outlook.Demo.zip)

Best Regards!

Hello,

Any progress on your project? I’ve added a VB version of demo, thought it might be helpful. If you have any features request, please post it here, We’d be happy to hear that.

[VB.NET]

Imports Aspose.Network.Data.OutlookClient

Module Module1

Sub Main()

Dim connection As Aspose.Network.Data.OutlookClient.OutlookConnection
Dim cmd As Aspose.Network.Data.OutlookClient.OutlookCommand
Dim adapter As Aspose.Network.Data.OutlookClient.OutlookDataAdapter
'init
connection = New OutlookConnection()
cmd = New OutlookCommand
adapter = New OutlookDataAdapter()

'print out available connections:
PrintAvailableConnection(connection)

Dim connectionList As ArrayList
connectionList = connection.GetConnectionList()

'choose the first connection
connection.ConnectionString = connectionList(0).ToString()
'set OutlookCommand’s connection
cmd.Connection = connection
'set adapter’s command
adapter.SelectCommand = cmd

'available folders:
PrintAvailableOutlookFolders(cmd)

'command text
cmd.CommandText = “SELECT * FROM Inbox”

Dim resultSet As System.Data.DataSet
resultSet = New DataSet()
adapter.Fill(resultSet)

'simply print out this dataset
PrintMessages(resultSet)

Console.WriteLine(vbNewLine & “press Enter to exit…”)
Console.Read()
End Sub

Sub PrintAvailableConnection(ByVal connection As Aspose.Network.Data.OutlookClient.OutlookConnection)
Dim connectionList As ArrayList
connectionList = connection.GetConnectionList()
Console.WriteLine(“Available connections to outlook:”)
For i As Integer = 0 To connectionList.Count - 1
Console.WriteLine(connectionList(i).ToString())
Next
End Sub

Sub PrintAvailableOutlookFolders(ByVal command As Aspose.Network.Data.OutlookClient.OutlookCommand)
Dim folders As Outlook.Folders
folders = command.GetFolders()
Console.WriteLine(“Available folders:”)
For i As Integer = 1 To folders.Count - 1
Console.WriteLine(folders.Item(i).Name)
Next
End Sub

Sub PrintMessages(ByVal resultSet As System.Data.DataSet)
Dim messages As System.Data.DataTable
messages = resultSet.Tables(0)
For i As Integer = 0 To messages.Rows.Count - 1
For j As Integer = 0 To messages.Columns.Count - 1
Console.Write(messages.Columns(j).ToString() & “:”)
Console.WriteLine(messages.Rows(i)(j).ToString())
Next
Next
End Sub

End Module

Demo project and required dll could be downloaded here:

[Http://www.aspose.com/products/Aspose.Network/tmp/outlookdemovb.zip ](https://forum.aspose.com/products/Aspose.Network/tmp/outlookdemovb.zip)

Thank you.

Hi,

I was wondering if the Network.Outlook API provides means of extracting messages and their attachments from .PST files.

Also, are there any plans to make the Network product available in Java?

Thanks.

DG.

Hello,

I would like to know how's your project using Aspose.Network.Data.OutlookClient.Are you using this dll or never?

If we port the Network product to Java, what features do you want ? Could you please tell me more about your scenarios?

Best regards.