In this section we will demonstrate how to use Aspose.network.Outlook. We will create a small application to load an outlook message file (TestMessage.msg) and display subject, from, to and body on a windows form.
Steps to Create My First Aspose.Network.Outlook Application
Follow the steps given below to create your first application using Aspose.Network.Outlook.
- Open your Visual Studio, click from the menu File > New > Project (Choose either C# or VB.NET Windows Application.
Figure: Snapshot of creating a new project in VS 2005.
- Import Aspose.Network dll in this application by right click on Reference from Solution Explorer.
- This will be windows based application which will only show the information contained in the message file.
Figure: Snapshot of application created in VS 2005
- Create an instance of MapiMessage by giving the path of the message file.
- Use the public properties to display the subject, from, to and body on the windows controls.
The implementation of above steps is demonstrated below in the following code snippet.
Use the following code behind the Load Msg File button or in OnLoad event of form.
[C#]
try
{
// load the outlook message file
Aspose.Network.Outlook.MapiMessage msg1 = Aspose.Network.Outlook.MapiMessage.FromFile(@"d:\TestMessage.msg");
// use the public properties to assign the values to controls
txtSubject.Text = msg1.Subject;
txtFrom.Text = msg1.SenderEmailAddress;
txtTo.Text = msg1.DisplayTo;
txtBody.Text = msg1.Body;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
[VB.NET]
Try
' load the outlook message file
Dim msg1 As Aspose.Network.Outlook.MapiMessage = Aspose.Network.Outlook.MapiMessage.FromFile("d:\TestMessage.msg")
' use the public properties to assign the values to controls
txtSubject.Text = msg1.Subject
txtFrom.Text = msg1.SenderEmailAddress
txtTo.Text = msg1.DisplayTo
txtBody.Text = msg1.Body
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try