private void button1_Click(object sender, EventArgs e) { try { OutLook.Application _app = new OutLook.Application(); OutLook.NameSpace _ns = _app.GetNamespace("MAPI"); OutLook.MAPIFolder inbox = _ns.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderInbox); _ns.SendAndReceive(true); dt = new DataTable("Inbox"); dt.Columns.Add("Subject", typeof(String)); dt.Columns.Add("Sender", typeof(String)); dt.Columns.Add("Body", typeof(String)); dt.Columns.Add("Date", typeof(String)); dataGridView.DataSource = dt; foreach (OutLook.MailItem item in inbox.Items) { dt.Rows.Add(new object[] { item.Subject, item.SenderName, item.HTMLBody, item.SentOn.ToLongDateString() + "" + item.SentOn.ToLongTimeString() }); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void sync() { Outlook.NameSpace ns = application.GetNamespace("MAPI"); ns.SendAndReceive(false); if (ns != null) { Marshal.ReleaseComObject(ns); } }
public void SendReceive(IAccount account) { // TODO: send/receive specific account NSOutlook.NameSpace session = _app.Session; try { session.SendAndReceive(false); } finally { ComRelease.Release(session); } }
public void SendReceive(IAccount account, AcaciaTask after) { if (after != null) { Watcher.Sync.AddEndTaskOnce(after); } // TODO: send/receive specific account NSOutlook.NameSpace session = _app.Session; try { session.SendAndReceive(false); } finally { ComRelease.Release(session); } }