protected void gvMessages_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "DisplayMessage")
        {
            pnlMessage.Visible = true;
            string msgURI = e.CommandArgument.ToString();

            try
            {
                // initialize exchange client
                NetworkCredential credential = new NetworkCredential(txtUsername.Text, Session["Password"].ToString(), txtDomain.Text);
                Aspose.Email.Exchange.ExchangeClient client = new Aspose.Email.Exchange.ExchangeClient(txtHost.Text, credential);

                lblMessage.ForeColor = Color.Green;
                lblMessage.Text = "Successfully connected to Microsoft Exchange Server.<br><hr>";

                Aspose.Email.Exchange.ExchangeMailboxInfo exchangeMailboxInfo = client.GetMailboxInfo();
                // get the message
                MailMessage msg = client.FetchMessage(msgURI);
                // sender name and address
                litFrom.Text = msg.From[0].DisplayName + " <" + msg.From[0].Address + ">";
                // to addresses
                litTo.Text = "";
                foreach (MailAddress address in msg.To)
                {
                    litTo.Text += address.DisplayName + " <" + address.Address + "> , ";
                }
                // cc addresses
                litCc.Text = "";
                foreach (MailAddress address in msg.CC)
                {
                    litCc.Text += address.DisplayName + " <" + address.Address + "> , ";
                }
                // subject
                litSubject.Text = msg.Subject;
                litBody.Text = msg.HtmlBody;
            }
            catch (Exception ex)
            {
                lblMessage.ForeColor = Color.Red;
                lblMessage.Text = "Error: " + ex.Message;
            }
        }
    }
    private void ListMessages()
    {
        lblMessage.ForeColor = Color.Green;
        lblMessage.Text = "";

        try
        {
            // initialize exchange client
            NetworkCredential credential = new NetworkCredential(txtUsername.Text, Session["Password"].ToString(), txtDomain.Text);
            Aspose.Email.Exchange.ExchangeClient client = new Aspose.Email.Exchange.ExchangeClient(txtHost.Text, credential);

            // get list of messages
            Aspose.Email.Exchange.ExchangeMailboxInfo exchangeMailboxInfo = client.GetMailboxInfo();
            Aspose.Email.Exchange.ExchangeMessageInfoCollection msgCollection = client.ListMessages(exchangeMailboxInfo.InboxUri);
            gvMessages.DataSource = msgCollection;
            gvMessages.DataBind();

            lblMessage.Text = "Successfully connected to Microsoft Exchange server.<br><hr>";
        }
        catch (Exception ex)
        {
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text = "Error: " + ex.Message;
        }
    }