dotnet-Snippets.com
Snippets: 75 | Registered User: 84 | Visitors online: 12
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Jobs

dotnet Jobs
Google Ads

Sri Lanka .NET 
                Forum Member
Create & Download Email Messages from Public Folders of Exch

Author: Guest
Programming Language: C# Rating:
not yet rated

Views: 184

Description:

This technical tip shows how to download Messages from Public Folders of Exchange Server. Microsoft Exchange Server provides the facility to create public folders and post messages in it. You can use ExchangeWebServiceClient class of Aspose.Email to connect to the Exchange Server and read/download messages and posts from Exchange public folders. Below is the sample source code to read all public folders/sub-folders and list/download messages inside these folders. This example will only work with MS Exchange Server 2007 or above due to EWS support.

To Test the code Download the following component: http://www.aspose.com/categories/.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




C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
 
class Program
{
    static string mailboxURI = "https://ex2010/ews/exchange.asmx"; // EWS
    static string username = "administrator";
    static string password = "pwd";
    static string domain = "ex2010.local";
 
    
    static void Main(string[] args)
    {
        try
        {
            ReadPublicFolders();
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
 
    private static void ReadPublicFolders()
    {
        NetworkCredential credential = new NetworkCredential(username, password, domain);
        ExchangeWebServiceClient client = new ExchangeWebServiceClient(mailboxURI, credential);
 
        ExchangeFolderInfoCollection folders = client.ListPublicFolders();
        foreach (ExchangeFolderInfo publicFolder in folders)
        {
            Console.WriteLine("Name: " + publicFolder.DisplayName);
            Console.WriteLine("Subfolders count: " + publicFolder.ChildFolderCount);
            ListMessagesFromSubFolder(publicFolder, client);
            
        }
    }
 
    private static void ListMessagesFromSubFolder(ExchangeFolderInfo publicFolder, ExchangeWebServiceClient client)
    {
        Console.WriteLine("Folder Name: " + publicFolder.DisplayName);
        ExchangeMessageInfoCollection msgInfoCollection = client.ListMessagesFromPublicFolder(publicFolder);
        foreach (ExchangeMessageInfo messageInfo in msgInfoCollection)
        {
            MailMessage msg = client.FetchMessage(messageInfo.UniqueUri);
            Console.WriteLine(msg.Subject);
            msg.Save(msg.Subject + ".msg", MailMessageSaveType.OutlookMessageFormat);
        }
 
        // Call this method recursively for any subfolders
        if (publicFolder.ChildFolderCount > 0)
        {
            ExchangeFolderInfoCollection subfolders = client.ListSubFolders(publicFolder);
            foreach (ExchangeFolderInfo subfolder in subfolders)
            {
                ListMessagesFromSubFolder(subfolder, client);
            }
        }
    }
}
 



Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to write an comment.)