You are here: Home Computer Programming Access & Read Email Messages from MS SharePoint Document Library

Access & Read Email Messages from MS SharePoint Document Library

February 20, 2012

Aspose.Email for .NET is a suite of .NET components for email programming within ASP.NET web applications, web services & Windows applications. It Supports Outlook PST, EML, MSG & MHT formats.




FOR IMMEDIATE RELEASE
(Free-Press-Release.com) February 20, 2012 -- Aspose.Email for .NET can help .NET applications to read email messages from Microsoft SharePoint document library. For accessing the files from SharePoint document library, SharePoint SDK must be installed on the system, which provides the necessary API for logging in and accessing files from the document library.

In the below code snippet, we will assume that an Outlook Message file (.msg) is already stored in the SharedDocument folder of SharePoint Document Library. We will utilize SharePoint SDK to get the message file in a stream and pass this stream to an instance of Aspose.Email's MailMessage class. MailMessage class will load the stream and parse the Outlook Message file. After that you can easily access the properties of MailMessage class e.g. Subject , TextBody , HtmlBody| etc and utilize that information in your Visual Studio project.

[C#]

// private members
private SPSite site = null;
private SPWeb web = null;

///
/// This Method is called throug Delegate elevatedGetSite which is definend in button2_Click
///
private void EstablishSharepoint()
{
site = new SPSite("http://localhost/Site1");
web = site.OpenWeb();
}

///
/// click event of a windows form button
///
///
///
private void button2_Click(object sender, EventArgs e)
{

SPSecurity.CodeToRunElevated elevatedGetSite = new SPSecurity.CodeToRunElevated(EstablishSharepoint);
SPSecurity.RunWithElevatedPrivileges(elevatedGetSite);

// path to the msg file stored in Shared Documents folder
SPFile msgFile = web.GetFile("Shared Documents/Test.msg");

// Read the file into a Memory Stream.
MemoryStream fileStream = new MemoryStream();
byte[] currentFileContent = msgFile.OpenBinary();
fileStream.Write(currentFileContent, 0, currentFileContent.Length);
fileStream.Position = 0;

// Create an instance of MailMessage class

// and pass the memory stream of .msg file to it
MailMessage msg = MailMessage.Load(fileStream, MessageFormat.Msg);
fileStream.Close();
fileStream.Dispose();

// access public properties of MailMessage class
Console.WriteLine("Subject: " + msg.Subject);
Console.WriteLine("From: " + msg.From.ToString());
Console.WriteLine("Text Body: " + msg.TextBody);
}

[VB.NET]

' private members
Private site As SPSite = Nothing
Private web As SPWeb = Nothing

'''

''' This Method is called throug Delegate elevatedGetSite which is definend in button2_Click
'''
Private Sub EstablishSharepoint()
site = New SPSite("http://localhost/Site1")
web = site.OpenWeb()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim elevatedGetSite As New SPSecurity.CodeToRunElevated(AddressOf EstablishSharepoint)
SPSecurity.RunWithElevatedPrivileges(elevatedGetSite)

' path to the msg file stored in Shared Documents folder

Dim msgFile As SPFile = web.GetFile("Shared Documents/Test.msg")

' Read the file into a Memory Stream.
Dim fileStream As New MemoryStream()
Dim currentFileContent As Byte() = msgFile.OpenBinary()
fileStream.Write(currentFileContent, 0, currentFileContent.Length)
fileStream.Position = 0

' Create an instance of MailMessage class
' and pass the memory stream of .msg file to it
Dim msg As MailMessage = MailMessage.Load(fileStream, MessageFormat.Msg)
fileStream.Close()
fileStream.Dispose()

' access public properties of MailMessage class
Console.WriteLine("Subject: " & msg.Subject)
Console.WriteLine("From: " & msg.From.ToString())
Console.WriteLine("Text Body: " & msg.TextBody)
End Sub

Overview: Aspose.Email for .NET

Aspose.Email for .NET is a set of components allowing developers to easily implement email functionality within their ASP.NET web applications, web services & Windows applications. It Supports Outlook PST, EML, MSG & MHT formats. It allows developers to work with SMTP, POP3, FTP & MS Exchange servers. It supports mail merge, iCalendar, customized header & body, header information, embedded files, Twitter & many more. It makes it easy to work with HTML or plain text emails & their attachments.

More about Aspose.Email for .NET

- Homepage of Aspose.Email for .NET: http://www.aspose.com/categories/.net-components/aspose.email-for-.net/default.aspx

- Download Aspose.Email for .NET: http://www.aspose.com/community/files/51/.net-components/aspose.email-for-.net/default.aspx

- More Technical Tips by Aspose.Email for .NET: http://www.aspose.com/documentation/.net-components/aspose.email-for-.net/knowledge-base.html

Contact Information
Aspose Pty Ltd, Suite 163,
79 Longueville Road

Lane Cove, NSW, 2066
Australia
http://www.aspose.com/
sales@aspose.com
Phone: 888.277.6734
Fax: 866.810.9465


free-press-release.com access properties of MailMessa     Access Read Email Subject     Access Read Email TextBody     accessing files from the docum     Microsoft SharePoint document     Read Outlook Message file     Read SharePoint email messages     SharePoint SDK

Share |


Contact Information

  • Name: sherazam

    Company: Aspose Pty Ltd

    Telephone: 888.277.6734

    Email: ***@aspose.com



People who viewed this press release also interested in the following topics: read eml files with sharepoint 2010, and sharepoint 2010 powershell ad eml file to document library.




Upcoming Trade ShowNew Press NewsNew Exclusive News More Press News

  • COMPUTEX 2012 When: 2012.06.05~2012.06.09
    Where: Taipei,Taiwan (China)
    Industry: Computer Hardware & Software
  • COMPUTEX TAIPEI
    COMPUTEX TAIPEI When: 2012.06.05~2012.06.09
    Where: Taipei,Taiwan (China)
    Industry: Computer Hardware & Software
  • E3 Expo 2012 When: 2012.06.05~2012.06.07
    Where: Los Angeles,States
    Industry: Computer Hardware & Software


  • Post your news to the World.See you news here immediately. It's easy and free!
    Create free account or Login.