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; } }
protected void brnSendEmail_Click(object sender, EventArgs e) { lblMessage.Text = ""; lblMessage.ForeColor = Color.Green; try { // initialize exchange client NetworkCredential credential = new NetworkCredential(txtUsername.Text, txtPassword.Text, txtDomain.Text); Aspose.Email.Exchange.ExchangeClient client = new Aspose.Email.Exchange.ExchangeClient(txtHost.Text, credential); // get mailbox and folders information Aspose.Email.Exchange.ExchangeMailboxInfo exchangeMailboxInfo = client.GetMailboxInfo(); lblMailboxURI.Text = exchangeMailboxInfo.MailboxUri; lblInboxURI.Text = exchangeMailboxInfo.InboxUri; lblSentItemsURI.Text = exchangeMailboxInfo.SentItemsUri; lblDraftsURI.Text = exchangeMailboxInfo.DraftsUri; lblCalendarURI.Text = exchangeMailboxInfo.CalendarUri; lblDeletedItemsURI.Text = exchangeMailboxInfo.DeletedItemsUri; lblMessage.Text = "Successfully connected to Microsoft Exchange server.<br><hr>"; } catch (Exception ex) { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Error: " + ex.Message; } }
protected void brnSendEmail_Click(object sender, EventArgs e) { lblMessage.Text = ""; lblMessage.ForeColor = Color.Green; try { // initialize exchange client NetworkCredential credential = new NetworkCredential(txtUsername.Text, txtPassword.Text, txtDomain.Text); Aspose.Email.Exchange.ExchangeClient client = new Aspose.Email.Exchange.ExchangeClient(txtHost.Text, credential); lblMessage.Text = "Successfully connected to Microsoft Exchange server.<br><hr>"; } catch (Exception ex) { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Error: " + ex.Message; } }
private void DownloadFile(string msgSequenceNumber, string format) { 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>"; // get the message MemoryStream stream = new MemoryStream(); MailMessage msg = client.FetchMessage(msgSequenceNumber); if (format == "eml") msg.Save(stream, MessageFormat.Eml); else msg.Save(stream, MessageFormat.Msg); stream.Position = 0; byte[] msgBytes = new byte[stream.Length]; stream.Read(msgBytes, 0, (int)stream.Length); Response.Clear(); Response.Buffer = true; Response.AddHeader("Content-Length", msgBytes.Length.ToString()); Response.AddHeader("Content-Disposition", "attachment; filename=Message." + format); Response.ContentType = "application/octet-stream"; Response.BinaryWrite(msgBytes); Response.End(); } catch (Exception ex) { lblMessage.ForeColor = Color.Red; lblMessage.Text = "Error: " + ex.Message; } }