Developer's Guide - EPiServer World
Developer's Guide - EPiServer World
Developer's Guide - EPiServer World
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Tutorials | 119<br />
Accessing a Mailbox<br />
The mailboxes in an account form a tree structure. The root mailbox is the only one which is explicitly referenced from<br />
the outside, but it is easy to get to any given mailbox using the ChildMailboxes property which is available on all<br />
mailboxes.<br />
IUser user = (IUser)StarCommunitySystem.<br />
CurrentContext.DefaultSecurity.GetUser(17);<br />
MailAccount account = WebmailHandler.GetMailAccount(user);<br />
Mailbox root = account.RootMailbox;<br />
Mailbox subMailbox = root.ChildMailboxes["name"];<br />
This way, you can access a mailbox by its name, or you can iterate over the ChildMailboxes as a list, depending on your<br />
needs.<br />
2.28.5 Getting Messages<br />
The centerpiece of any Webmail implementation is the messages. This article will show examples of how to access the<br />
actual messages.<br />
Import Necessary Namespaces<br />
First, import the necessary namespaces that will be needed for this. The namespaces StarCommunity.Core,<br />
StarCommunity.Core.Modules.Security and StarCommunity.Modules.VideoGallery<br />
The StarCommunity.Modules.VideoGallery namespace contains classes for creating video galleries and uploading videos<br />
for transcoding into a web friendly format, like Adobe Flash Video.<br />
StarCommunity.Modules.Webmail are described by clicking on their respective names. Make sure you also add the<br />
mentioned assemblies as references, as mentioned in section 1.1.1.<br />
using StarCommunity.Core;<br />
using StarCommunity.Core.Modules.Security;<br />
using StarCommunity.Modules.Webmail;<br />
Getting a List of Messages<br />
To get a list of messages, we first get the mail account of the user, we then call the GetMessages method in the<br />
WebmailHandler, specifying the mailbox, the paging information (page size and page number to retrieve) and the sort<br />
order.<br />
IUser user = (IUser)StarCommunitySystem.<br />
CurrentContext.DefaultSecurity.GetUser(17);<br />
MailAccount account = WebmailHandler.GetMailAccount(user);<br />
MessageSortOrder order =<br />
new MessageSortOrder(MessageSortField.Date, SortDirection.Descending);<br />
Mailbox mbox = account.RootMailbox;<br />
int totalHits = 0;<br />
MessageCollection messages = WebmailHandler.GetMessages(mbox, 1, 20, out<br />
totalHits, order);<br />
© <strong>EPiServer</strong> AB