static public string GetMessageId(outlook.MailItem mail)
        {
            var    propertyAccessor = mail.PropertyAccessor;
            string message_id       = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1035001E").ToString();

            return(message_id);
        }
예제 #2
0
 public override void Run()
 {
     try
     {
         if (!(this.Owner is LeadDetailController))
         {
             return;
         }
         LeadDetailController leadPresenter = (LeadDetailController)this.Owner;
         LateBindingApi.Core.Factory.Initialize();
         Outlook.Application outlookApplication = new Outlook.Application();
         Outlook.MailItem    KatrinEmal         = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
         object emailToObject = leadPresenter.ObjectEntity.GetType().GetProperty("EmailAddress").GetValue(leadPresenter.ObjectEntity, null);
         string emailTo       = emailToObject == null ? string.Empty : emailToObject.ToString();
         if (!string.IsNullOrEmpty(emailTo))
         {
             KatrinEmal.Recipients.Add(emailTo);
         }
         KatrinEmal.Importance = OlImportance.olImportanceNormal;
         KatrinEmal.Display();
     }
     catch (Exception ex)
     {
         MessageService.ShowException(ex, ResourceService.GetString("EmailExceptionTip"));
     }
 }
        static public Hashtable GetAttachments(outlook.MailItem mail)
        {
            /*
             *
             * Gets the attachments of selected mail of outlook mail items.
             * :Param outlook.MailItem mail : gives the selected mail item from the outlook.
             * returns the hashtable (dictionary) value of the attachemts.
             */
            System.IO.FileStream inFile;
            Hashtable            attach = new Hashtable();

            string[] strattch = new string[4];
            foreach (outlook.Attachment attach1 in mail.Attachments)
            {
                string filename = Tools.GetAppFolderPath() + attach1.FileName;
                attach1.SaveAsFile(filename);
                inFile = new System.IO.FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                byte[] datas     = new Byte[inFile.Length];
                long   bytesRead = inFile.Read(datas, 0, (int)inFile.Length);
                inFile.Close();
                string fdata = System.Convert.ToBase64String(datas);
                attach.Add(attach1.FileName, fdata);
                strattch[0] = attach1.FileName;
                System.IO.File.Delete(filename);
            }
            return(attach);
        }
예제 #4
0
        public void OnGenerateDayReport(object sender, EventArgs e)
        {
            LateBindingApi.Core.Factory.Initialize();
            Outlook.Application outlookApplication = new Outlook.Application();

            DateTime    thisDay       = DateTime.Today;
            DateTime    nextDay       = thisDay.AddDays(1);
            IEnumerable taskList      = GetTasks(thisDay);
            var         projectIdList = taskList.AsQueryable().Select("ProjectId").Cast <Guid>().Distinct <Guid>();

            if (projectIdList.ToList().Count <= 0)
            {
                XtraMessageBox.Show(Properties.Resources.NoTaskTip,
                                    Properties.Resources.Katrin,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information,
                                    MessageBoxDefaultButton.Button1);
                return;
            }
            foreach (Guid projectId in projectIdList)
            {
                Outlook.MailItem KatrinEmal = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
                KatrinEmal.Subject = "";
                string emailTo        = "";
                string sourceHtmlBody = KatrinEmal.HTMLBody;
                KatrinEmal.HTMLBody = InitEmailMessage(out emailTo, thisDay, nextDay, projectId, taskList);
                if (!string.IsNullOrEmpty(emailTo))
                {
                    KatrinEmal.Recipients.Add(emailTo);
                }
                KatrinEmal.Importance = OlImportance.olImportanceNormal;
                KatrinEmal.Display();
            }
        }
예제 #5
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook
            Outlook.Application outlookApplication = new Outlook.Application();

            // get inbox
            Outlook._NameSpace outlookNS   = outlookApplication.GetNamespace("MAPI");
            Outlook.MAPIFolder inboxFolder = outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);

            // setup gui
            listViewInboxFolder.Items.Clear();
            labelItemsCount.Text = string.Format("You have {0} e-mails.", inboxFolder.Items.Count);

            // we fetch the inbox folder items.
            foreach (COMObject item in inboxFolder.Items)
            {
                // not every item in the inbox is a mail item
                Outlook.MailItem mailItem = item as Outlook.MailItem;
                if (null != mailItem)
                {
                    ListViewItem newItem = listViewInboxFolder.Items.Add(mailItem.SenderName);
                    newItem.SubItems.Add(mailItem.Subject);
                }
            }

            // close outlook and dispose
            outlookApplication.Quit();
            outlookApplication.Dispose();
        }
예제 #6
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook by trying to access running application first
            Outlook.Application outlookApplication = new Outlook.Application(true);

            // create MailItem and register close event
            Outlook.MailItem mailItem = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
            mailItem.CloseEvent += new NetOffice.OutlookApi.MailItem_CloseEventHandler(mailItem_CloseEvent);

            // BodyFormat is not available in Outlook 2000, we check at runtime the property is available
            if (mailItem.EntityIsAvailable("BodyFormat"))
            {
                mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
            }
            mailItem.Body    = "ExampleBody";
            mailItem.Subject = "ExampleSubject";
            mailItem.Display();
            mailItem.Close(OlInspectorClose.olDiscard);

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();
        }
 public override void Run()
 {
     try
     {
         ProjectWeekReportDetailController projectWeekReportController = (ProjectWeekReportDetailController)this.Owner;
         if (!(this.Owner is ProjectWeekReportDetailController))
         {
             return;
         }
         LateBindingApi.Core.Factory.Initialize();
         Outlook.Application outlookApplication = new Outlook.Application();
         Outlook.MailItem    KatrinEmal         = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
         KatrinEmal.Subject = projectWeekReportController.ObjectName;
         string emailTo = "";
         KatrinEmal.Display();
         string sourceHtmlBody = KatrinEmal.HTMLBody;
         string emailBody      = InitEmailMessage(out emailTo);
         emailBody          += sourceHtmlBody;
         KatrinEmal.HTMLBody = emailBody;
         if (!string.IsNullOrEmpty(emailTo))
         {
             KatrinEmal.Recipients.Add(emailTo);
         }
         KatrinEmal.Importance = OlImportance.olImportanceNormal;
     }
     catch (Exception ex)
     {
         MessageService.ShowException(ex, ResourceService.GetString("EmailExceptionTip"));
     }
 }
예제 #8
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook by trying to access running application first
            Outlook.Application outlookApplication = new Outlook.Application(true);

            // get inbox
            Outlook._NameSpace outlookNS   = outlookApplication.GetNamespace("MAPI");
            Outlook.MAPIFolder inboxFolder = outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);

            // setup ui
            listViewInboxFolder.Items.Clear();
            labelItemsCount.Text = string.Format("You have {0} e-mail(s).", inboxFolder.Items.Count);

            // we fetch the inbox folder items by a custom enumerator
            foreach (ICOMObject item in inboxFolder.Items)
            {
                // not every item in the inbox is a mail item
                Outlook.MailItem mailItem = item as Outlook.MailItem;
                if (null != mailItem)
                {
                    ListViewItem newItem = listViewInboxFolder.Items.Add(mailItem.SenderName);
                    newItem.SubItems.Add(mailItem.Subject);
                }
            }

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();
        }
예제 #9
0
파일: Test03.cs 프로젝트: zyfzgt/NetOffice
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime            startTime   = DateTime.Now;

            try
            {
                // start outlook
                application = new Outlook.Application();
                NetOffice.OutlookSecurity.Suppress.Enabled = true;

                // Create a new MailItem.
                Outlook.MailItem mailItem = application.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;

                // prepare item and send
                mailItem.Recipients.Add("*****@*****.**");
                mailItem.Subject = "NetOffice Test Mail";
                mailItem.Body    = "This is a NetOffice test mail from the MainTests.(C#)";
                mailItem.Send();

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    application.Quit();
                    application.Dispose();
                }
            }
        }
예제 #10
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime            startTime   = DateTime.Now;

            try
            {
                // start outlook
                application = new Outlook.Application(true);
                NetOffice.OutlookSecurity.Suppress.Enabled = true;

                // Get inbox
                Outlook._NameSpace outlookNS   = application.GetNamespace("MAPI");
                Outlook.MAPIFolder inboxFolder = outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);

                Outlook._Items items = inboxFolder.Items;
                COMObject      item  = null;
                int            i     = 1;
                do
                {
                    if (null == item)
                    {
                        item = items.GetFirst() as COMObject;
                    }

                    // not every item is a mail item
                    Outlook.MailItem mailItem = item as Outlook.MailItem;
                    if (null != mailItem)
                    {
                        Console.WriteLine(mailItem.SenderName);
                    }

                    if (null != item)
                    {
                        item.Dispose();
                    }

                    item = items.GetNext() as COMObject;
                    i++;
                } while (null != item);

                return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, string.Format("{0} Inbox Items.", items.Count)));
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    if (!application.FromProxyService)
                    {
                        application.Quit();
                    }
                    application.Dispose();
                }
            }
        }
        public string Name_get(outlook.MailItem mail)
        {
            string email = Tools.GetHeader(mail);
            object doc   = this.openerp_connect.Execute("plugin.handler", "document_get", email);

            object[] name = (object[])doc;
            return(name[3].ToString());
        }
        static public string GetHeader(outlook.MailItem mail)
        {
            var propertyAccessor = mail.PropertyAccessor;
            //string HEADERS = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/string/{3f0a69e0-7f56-11d2-b536-00aa00bbb6e6}/urn:schemas:httpmail:content-disposition-type").ToString();
            string HEADERS = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E").ToString();

            return(HEADERS);
        }
예제 #13
0
 private static void SendMail(Outlook.Application application)
 {
     Outlook.MailItem mailItem = application.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
     mailItem.Recipients.Add("*****@*****.**");
     mailItem.Subject = "Concept Test - SuppressOutlookSecurity";
     mailItem.Body    = "This is a test mail from NetOffice concept test.";
     mailItem.Send();
 }
예제 #14
0
 void i_NewInspectorEvent(OutLook._Inspector Inspector)
 {
     _newMail = Inspector.CurrentItem as OutLook.MailItem;
     if (_newMail == null || !String.IsNullOrEmpty(_newMail.EntryID))
     {
         return;
     }
     _newMail.SendEvent += newMail_SendEvent;
 }
 /// <summary>
 /// Called when a new item has entered the stack
 /// </summary>
 /// <param name="Item"></param>
 private void items_ItemAdd(object Item)
 {
     Outlook.MailItem mail = (Outlook.MailItem)Item;
     if (Item != null)
     {
         if (mail.MessageClass == "IPM.Note" &&
             mail.Subject.ToUpper().Contains(SEARCH_MAIL_TEXT.ToUpper()))
         {
             ParsingTaskExecuting.Enqueue(new WeekParser(outlookApp, mail.Body));
         }
     }
 }
        public void Open_Document(outlook.MailItem mail)
        {
            /*
             * To open document attached in a url.returns the model_id and res_id of the document
             * :Param outlook.MailItem mail: Outlook mails.
             */

            string email = Tools.GetHeader(mail);
            object doc   = this.openerp_connect.Execute("plugin.handler", "document_get", email);

            object[] url = (object[])doc;
            this.RedirectWeb(url[2].ToString());
        }
예제 #17
0
        public TestResult DoTest()
        {
            Outlook.Application application = null;
            DateTime            startTime   = DateTime.Now;

            try
            {
                // start outlook
                application = new Outlook.Application(true);
                NetOffice.OutlookSecurity.Suppress.Enabled = true;

                Outlook.MailItem mailItem = application.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
                mailItem.CloseEvent += new NetOffice.OutlookApi.MailItem_CloseEventHandler(mailItem_CloseEvent);

                // BodyFormat is not available in Outlook 2000
                // we check at runtime is property is available
                if (mailItem.EntityIsAvailable("BodyFormat"))
                {
                    mailItem.BodyFormat = OlBodyFormat.olFormatPlain;
                }
                mailItem.Body    = "NetOffice C# Test06" + DateTime.Now.ToLongTimeString();
                mailItem.Subject = "Test06";
                mailItem.Display();
                mailItem.Close(OlInspectorClose.olDiscard);

                if (_closeEventCalled)
                {
                    return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, ""));
                }
                else
                {
                    return(new TestResult(false, DateTime.Now.Subtract(startTime), "CloseEvent not triggered.", null, ""));
                }
            }
            catch (Exception exception)
            {
                return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, ""));
            }
            finally
            {
                if (null != application)
                {
                    if (!application.FromProxyService)
                    {
                        application.Quit();
                    }
                    application.Dispose();
                }
            }
        }
예제 #18
0
파일: Program.cs 프로젝트: Jodsalz/DevDB
        private static void sync_end()                          // Function starts through event (SyncEndEvent)
        {
            Console.WriteLine("enter syncend event");

            string subject = "leer";
            string body    = "leer";

            Outlook.MailItem mailItem = null;

            Console.WriteLine("Entered sync_end Event with inboxitems: " + inboxFolder.Items.Count);

            for (int i = inboxFolder.Items.Count; i > 0; i--)
            {
                mailItem = inboxFolder.Items[i] as Outlook.MailItem;


                // Downloads Body if not downloaded yet (IMAP Problems)
                if (mailItem.DownloadState != OlDownloadState.olFullItem)
                {
                    Console.WriteLine("again");
                    mailItem.MarkForDownload = OlRemoteStatus.olMarkedForDownload;
                    outlookNS.SendAndReceive(false);
                    break;                                                                      // Replace with threads maybe?
                }

                // Calls Database for Insert
                if (mailItem != null && mailItem.Subject.StartsWith("DevDB Einbuchung", System.StringComparison.CurrentCultureIgnoreCase) && mailItem.DownloadState == OlDownloadState.olFullItem)
                {
                    subject = mailItem.Subject;
                    body    = mailItem.Body;
                    einbuchung_vorgang(body);
                    mailItem.Delete();
                }

                // Calls Database for Delete
                else if (mailItem != null && mailItem.Subject.StartsWith("DevDB 2", System.StringComparison.CurrentCultureIgnoreCase) && mailItem.DownloadState == OlDownloadState.olFullItem)
                {
                    subject = mailItem.Subject;
                    body    = mailItem.Body;
                    ausbuchung_vorgang(body);
                    mailItem.Delete();
                }
                else
                {
                    Console.WriteLine("doesn't match rules... deleted...");
                    mailItem.Delete();
                }
            }
            Console.WriteLine("Left Event");
        }
        public object[] RedirectPartnerPage(outlook.MailItem mail)
        {
            /*
             *
             * Will Redirect to the web-browser and open partner.
             * If it will not found partner in res.partner (in contact) then
             * it will open the contact form to create a partner.
             * :Param outlook.MailItem mailItem : Outlook Mail item
             */
            string email_id = mail.SenderEmailAddress.ToString();

            Object[] contact = (Object[])this.openerp_connect.Execute("plugin.handler", "partner_get", email_id);
            return(contact);
        }
예제 #20
0
        public void OnSetOpportunitySuccess(object sender, EventArgs e)
        {
            LateBindingApi.Core.Factory.Initialize();
            Outlook.Application outlookApplication = new Outlook.Application();
            Outlook.MailItem    KatrinEmal         = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
            string emailTo = DynamicEntity.EmailAddress;

            if (!string.IsNullOrEmpty(emailTo))
            {
                KatrinEmal.Recipients.Add(emailTo);
            }
            KatrinEmal.Importance = OlImportance.olImportanceNormal;
            KatrinEmal.Display();
        }
        public Boolean PushMail(outlook.MailItem mail, string model, int thread_id)
        {
            /*
             *
             * This will push the mail as per the selected items from the list.
             *  :Param outlook.MailItem mail: selected mail from the outlook.
             *  :Param string model : Model name to push.
             *  :Param int thread_id : Thread id of the mail.
             * If mail pushed successfully then it returns true.
             * return False if mail Already Exist.
             *
             */
            OpenERPOutlookPlugin openerp_outlook = Cache.OpenERPOutlookPlugin;
            OpenERPConnect       openerp_connect = openerp_outlook.Connection;
            ArrayList            args            = new ArrayList();
            Hashtable            vals            = new Hashtable();
            string email;

            if (Tools.GetHeader(mail) != null)
            {
                email = Tools.GetHeader(mail);     //TODO: Outlook.MailItem Should be Converted into MIME Message
            }
            else
            {
                email = "";
            }

            args.Add(model);
            args.Add(email.ToString());
            args.Add(thread_id);
            Hashtable attachments = Tools.GetAttachments(mail);

            args.Add(mail.Body);
            args.Add(mail.HTMLBody);
            args.Add(attachments);
            object push_mail = this.Connection.Execute("plugin.handler", "push_message_outlook", args.ToArray());

            object[] push = (object[])push_mail;
            if (Convert.ToInt32(push[1]) == 0)
            {
                MessageBox.Show(push[3].ToString());
            }
            else
            {
                this.RedirectWeb(push[2].ToString());
            }
            return(true);
        }
예제 #22
0
파일: Outlok.cs 프로젝트: Jodsalz/Forms
 private void outlook_newmail(string s)
 {
     foreach (COMObject item in inboxFolder.Items)
     {
         Outlook.MailItem mailItem = item as Outlook.MailItem;
         if (mailItem != null && mailItem.Subject == "DevDB Einbuchung")
         {
             mailItem.Move(einbuchung);
             //body = mailItem.Body;
         }
         else if (mailItem != null && mailItem.Subject == "DevDB Ausbuchung")
         {
             mailItem.Move(ausbuchung);
             //body = mailItem.Body;
         }
     }
 }
예제 #23
0
        private void ProcessOneItem(Outlook.MailItem item)
        {
            Trace.TraceInformation($"Processing email from {item.SenderEmailAddress} \"{ item.Subject}\" sent on  {item.SentOn}");
            foreach (Outlook.Attachment att in item.Attachments)
            {
                int epoch       = (int)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
                var tempAttPath = Environment.ExpandEnvironmentVariables($"%TEMP%\\{epoch}_{att.FileName}");
                att.SaveAsFile(tempAttPath);
                Start(tempAttPath);
                return;
            }
            var links = FindUrlsInText(item.Body);

            foreach (var l in links)
            {
                Start(l);
            }
        }
예제 #24
0
        public void GenerateDayReport()
        {
            try
            {
                LateBindingApi.Core.Factory.Initialize();
                Outlook.Application outlookApplication = new Outlook.Application();

                DateTime    thisDay       = DateTime.Today;
                DateTime    nextDay       = thisDay.AddDays(1);
                IEnumerable taskList      = GetTasks(thisDay);
                var         projectIdList = taskList.AsQueryable().Select("ProjectId").Cast <Guid>().Distinct <Guid>();
                if (projectIdList.ToList().Count <= 0)
                {
                    XtraMessageBox.Show(StringParser.Parse("NoTaskTip"),
                                        StringParser.Parse("Katrin"),
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information,
                                        MessageBoxDefaultButton.Button1);
                    return;
                }
                foreach (Guid projectId in projectIdList)
                {
                    Outlook.MailItem KatrinEmal = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
                    KatrinEmal.Subject = "";
                    string emailTo = "";
                    KatrinEmal.Display();
                    string sourceHtmlBody = KatrinEmal.HTMLBody;
                    string emailBody      = InitEmailMessage(out emailTo, thisDay, nextDay, projectId, taskList);
                    emailBody          += sourceHtmlBody;
                    KatrinEmal.HTMLBody = emailBody;
                    if (!string.IsNullOrEmpty(emailTo))
                    {
                        KatrinEmal.Recipients.Add(emailTo);
                    }
                    KatrinEmal.Importance = OlImportance.olImportanceNormal;
                }
            }
            catch (Exception ex)
            {
                MessageService.ShowException(ex, ResourceService.GetString("EmailExceptionTip"));
            }
        }
예제 #25
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook
            Outlook.Application outlookApplication = new Outlook.Application();

            // create a new MailItem.
            Outlook.MailItem mailItem = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;

            // prepare item and send
            mailItem.Recipients.Add(textBoxReciever.Text);
            mailItem.Subject = textBoxSubject.Text;
            mailItem.Body    = textBoxBody.Text;
            mailItem.Send();

            // close outlook and dispose
            outlookApplication.Quit();
            outlookApplication.Dispose();

            HostApplication.ShowFinishDialog("Done!", null);
        }
 public void OnGenerateWeekReport(object sender, EventArgs e)
 {
     try
     {
         LateBindingApi.Core.Factory.Initialize();
         Outlook.Application outlookApplication = new Outlook.Application();
         Outlook.MailItem    KatrinEmal         = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
         KatrinEmal.Subject = this.DynamicEntity.Name;
         string emailTo = "";
         KatrinEmal.HTMLBody = InitEmailMessage(out emailTo);
         if (!string.IsNullOrEmpty(emailTo))
         {
             KatrinEmal.Recipients.Add(emailTo);
         }
         KatrinEmal.Importance = OlImportance.olImportanceNormal;
         KatrinEmal.Display();
     }
     catch
     {
     }
 }
예제 #27
0
        private void listViewSearchResults_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                if (listViewSearchResults.SelectedItems.Count > 0)
                {
                    Customer selectedCustomer = listViewSearchResults.SelectedItems[0].Tag as Customer;

                    // create MailItem
                    Outlook.MailItem mailItem = Addin.Application.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;
                    mailItem.BodyFormat = OlBodyFormat.olFormatRichText;
                    mailItem.To         = selectedCustomer.Mail;
                    mailItem.Body       = "Hello " + selectedCustomer.Name;
                    mailItem.Subject    = "<Insert Subject>";
                    mailItem.Display();
                    mailItem.Dispose();
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(this, exception.Message, "An error occured", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #28
0
        private void buttonStartExample_Click(object sender, EventArgs e)
        {
            // start outlook by trying to access running application first
            Outlook.Application outlookApplication = COMObject.CreateByRunningInstance <Outlook.Application>();

            // create a new MailItem.
            Outlook.MailItem mailItem = outlookApplication.CreateItem(OlItemType.olMailItem) as Outlook.MailItem;

            // prepare item and send
            mailItem.Recipients.Add(textBoxReciever.Text);
            mailItem.Subject = textBoxSubject.Text;
            mailItem.Body    = textBoxBody.Text;
            mailItem.Send();

            // close outlook and dispose
            if (!outlookApplication.FromProxyService)
            {
                outlookApplication.Quit();
            }
            outlookApplication.Dispose();

            HostApplication.ShowFinishDialog("Done!", null);
        }
예제 #29
0
파일: Form1.cs 프로젝트: tinmanjk/NetOffice
        private void ListInBoxFolder(Outlook.MAPIFolder inboxFolder)
        {
            // setup ui
            listView1.Items.Clear();

            // we fetch the inbox folder items
            Outlook._Items items = inboxFolder.Items;
            ICOMObject     item  = null;
            int            i     = 1;

            do
            {
                if (null == item)
                {
                    item = items.GetFirst() as ICOMObject;
                    if (null == item)
                    {
                        break;
                    }
                }

                // not every item is a mail item
                Outlook.MailItem mailItem = item as Outlook.MailItem;
                if (null != mailItem)
                {
                    ListViewItem newItem = listView1.Items.Add(mailItem.SenderName);
                    newItem.SubItems.Add(mailItem.Subject);
                }

                item.Dispose();
                item = items.GetNext() as ICOMObject;
                i++;
            } while (null != item);

            // dipsose items and childs
            items.Dispose();
        }
        public static MailItem GetEmail(string subject, string recipientEmail, DateTime maxAgeTimeStamp, int waitSeconds)
        {
            const int    checkIntervalSeconds = 15;
            const string prSmtpAddress        = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E";

            if (Process.GetProcessesByName("outlook").Length == 0)
            {
                Process.Start("outlook.exe");
            }

            var item = new MailItem();

            NetOffice.OutlookApi.MailItem oItem = null;
            var match = false;

            try
            {
                Application app = new Application();
                _NameSpace  ns  = app.GetNamespace("MAPI");
                ns.Logon(null, null, false, false);

                MAPIFolder inboxFolder = ns.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
                _Items     oItems      = inboxFolder.Items;
                oItems.Sort("[ReceivedTime]", false);
                Console.WriteLine("DBG: Started looking for email at {0}", DateTime.Now);
                for (int j = 0; j <= waitSeconds; j = j + checkIntervalSeconds)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(checkIntervalSeconds));
                    for (int i = oItems.Count; i > 1; i--)
                    {
                        oItem = (NetOffice.OutlookApi.MailItem)oItems[i];
                        Console.WriteLine("DBG: Checking mail at {0} => found mail with timestamp: { 1}", DateTime.Now.ToLongTimeString(), oItem.SentOn.ToLongTimeString());
                        if ((oItem.ReceivedTime - maxAgeTimeStamp).TotalSeconds < 0)
                        {
                            break;
                        }
                        if (oItem.Subject.IsRegExMatch(subject) && oItem.Recipients.Single().PropertyAccessor.GetProperty(prSmtpAddress).ToString().Equals(recipientEmail))
                        {
                            match = true;
                            break;
                        }
                        //Console.WriteLine("Subject: {0}", item.Subject);
                        //Console.WriteLine("Sent: {0} {1}", item.SentOn.ToLongDateString(), item.SentOn.ToLongTimeString());
                    }
                    if (match)
                    {
                        break;
                    }
                }
            }
            catch (System.Runtime.InteropServices.COMException)
            {
                throw new Exception("ERROR: retrieving the email failed due to System.Runtime.InteropServices.COMException");
            }

            if (match)
            {
                item.EntryId      = oItem.EntryID;
                item.Subject      = oItem.Subject;
                item.SentDate     = oItem.SentOn.ToLongDateString();
                item.SentTime     = oItem.SentOn.ToLongTimeString();
                item.ReceivedDate = oItem.ReceivedTime.ToLongDateString();
                item.ReceivedTime = oItem.ReceivedTime.ToLongTimeString();
                item.Body         = oItem.Body;
                item.HtmlBody     = oItem.HTMLBody;
                item.HasMessage   = true;
                item.PrintInfo();
            }
            else
            {
                Console.WriteLine("DBG: Couldn't find message with subject matching {0} and recipient {1}", subject, recipientEmail);
            }
            Console.WriteLine("DBG: Finished looking for email at {0}", DateTime.Now);
            return(item);
        }