コード例 #1
0
        private static Appointment LookForNextAppointment(string textToSearch)
        {
            Microsoft.Office.Interop.Outlook.Application oApp = null;
            Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder CalendarFolder = null;
            Microsoft.Office.Interop.Outlook.Items outlookCalendarItems = null;

            oApp = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace = oApp.GetNamespace("MAPI"); ;
            CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
            outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.Sort("[Start]");
            var now = DateTime.Now.Date.ToString("g");
            var nowIn1Year = DateTime.Now.Date.AddYears(1).ToString("g");
            outlookCalendarItems = outlookCalendarItems.Restrict($"[Start] >= \"{now}\" AND [End] < \"{nowIn1Year}\" ");

            foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
            {
                var subject = item.Subject;
                if (subject.IndexOf(textToSearch,StringComparison.InvariantCultureIgnoreCase)!=-1)
                {
                    return new Appointment() { Subject = subject, Start = item.Start };
                }
            }
            return null;
        }
コード例 #2
0
ファイル: RepNorLo10.cs プロジェクト: andresp11/LancNeoAPL
        public static Boolean SendEmailWithOutlook(string mailDirection, string mailSubject, string mailContent, string nombre, string filename)
        {
            try
            {
                Microsoft.Office.Interop.Outlook._Application oApp = new Microsoft.Office.Interop.Outlook.Application();

                Microsoft.Office.Interop.Outlook.NameSpace ns = oApp.GetNamespace("MAPI");
//                var f = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

                System.Threading.Thread.Sleep(1000);

                var mailItem = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                mailItem.Subject  = "Informe preliminar de la obra: " + mailSubject;
                mailItem.HTMLBody = "Enviamos los resultados preliminares de las pruebas de compresión del mortero y concreto a edades tempranas de la obra " + mailSubject
                                    + "<br> en archivo adjunto. <br> <br> Estamos a sus ordenes para cualquier aclaración";
                mailItem.To = mailDirection;
                mailItem.Attachments.Add(nombre, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue,
                                         1, filename);
                mailItem.Send();
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
            }
            return(true);
        }
コード例 #3
0
ファイル: OutboxMonitor.cs プロジェクト: killbug2004/WSProf
        private static readonly object _lock = new object(); // Sync the processing of items in the Outbox

        public OutboxMonitor(Microsoft.Office.Interop.Outlook.Application application)
        {
            try
            {
                _application = application;
                _ns = _application.GetNamespace("MAPI");
                _outbox = _ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
                _items = _outbox.Items;
                _items.ItemAdd += Items_ItemAdd;

                SubmitNonDeferredItems();
                SyncroniseDeferredSendStore();
                CreateSubmitWorkerThreads();

				Logger.LogInfo("Secure File Transfer Outbox monitor created and configured.");
            }
            catch (Exception ex)
            {
                Dispose();

                Logger.LogError(ex);
                Logger.LogError("Failed to create OutboxMonitor. Disable DeferredSend");

                throw;
            }
        }
コード例 #4
0
        public static void CheckMailToExecute()
        {
            try
            {
                Microsoft.Office.Interop.Outlook.Application myApp         = new Microsoft.Office.Interop.Outlook.ApplicationClass();
                Microsoft.Office.Interop.Outlook.NameSpace   mapiNameSpace = myApp.GetNamespace("MAPI");
                Microsoft.Office.Interop.Outlook.MAPIFolder  myInbox       = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

                Microsoft.Office.Interop.Outlook.Items oItems = myInbox.Items.Restrict("[UnRead] = True");

                foreach (var item in oItems)
                {
                    if (item is Microsoft.Office.Interop.Outlook.MailItem)
                    {
                        Microsoft.Office.Interop.Outlook.MailItem mail = (Microsoft.Office.Interop.Outlook.MailItem)item;
                        if (mail.UnRead && mail.Subject.StartsWith("MC"))
                        {
                            mail.UnRead = false;
                            ExecuteMail(mail);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(ex.Message);
            }
        }
コード例 #5
0
ファイル: Correo.cs プロジェクト: Kraker23/Utilities
        /// <summary>
        /// para enviar correos desde la cuenta del outlook instalada en tu ordinador
        /// </summary>
        /// <param name="mailDirection"> el destino del correo </param>
        /// <param name="mailSubject"> el asunto del correo </param>
        /// <param name="mailContent">el contenido del correo </param>
        public string sendMail(string mailDirection, string mailSubject, string mailContent)
        {
            try
            {
                var oApp = new Microsoft.Office.Interop.Outlook.Application();

                Microsoft.Office.Interop.Outlook.NameSpace ns = oApp.GetNamespace("MAPI");
                var f = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

                System.Threading.Thread.Sleep(1000);

                var mailItem = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                mailItem.Subject  = mailSubject;
                mailItem.HTMLBody = mailContent;
                mailItem.To       = mailDirection;
                mailItem.Send();
                return(string.Empty);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);

                return(ex.Message);
            }
        }
コード例 #6
0
 public OutlookUtil()
 {
     //
     // TODO: Add constructor logic here
     //
     myApp  = new Microsoft.Office.Interop.Outlook.ApplicationClass();
     myName = myApp.GetNamespace("MAPI");
     myName.Logon("Outlook", "", false, true);
 }
コード例 #7
0
 public Outlook()
 {
     _ns    = _application.Session;
     _inbox = _ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
     _items = _inbox.Items;
     foreach (var item in _items)
     {
         var mail    = item as Microsoft.Office.Interop.Outlook.MailItem;
         var subject = mail.Subject;
     }
 }
コード例 #8
0
        /// <summary>
        /// Gets a list of all events in outlook
        /// </summary>
        public static List <CalendarEvent> GetAllEvents()
        {
            List <CalendarEvent> events = new List <CalendarEvent>();

            Microsoft.Office.Interop.Outlook.Application oApp                 = null;
            Microsoft.Office.Interop.Outlook.NameSpace   mapiNamespace        = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder  CalendarFolder       = null;
            Microsoft.Office.Interop.Outlook.Items       outlookCalendarItems = null;

            oApp           = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace  = oApp.GetNamespace("MAPI");
            CalendarFolder = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar); outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.IncludeRecurrences = true;

            CalendarEvent cEvent = null;

            foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
            {
                cEvent = null;

                if (item.IsRecurring)
                {
                    Microsoft.Office.Interop.Outlook.RecurrencePattern rp = item.GetRecurrencePattern();
                    DateTime first = new DateTime(2008, 8, 31, item.Start.Hour, item.Start.Minute, 0);
                    DateTime last  = new DateTime(2008, 10, 1);
                    Microsoft.Office.Interop.Outlook.AppointmentItem recur = null;

                    for (DateTime cur = first; cur <= last; cur = cur.AddDays(1))
                    {
                        try
                        {
                            recur  = rp.GetOccurrence(cur);
                            cEvent = new CalendarEvent(recur.GlobalAppointmentID, recur.Start, recur.End, recur.Location, recur.Subject, recur.Body);
                        }
                        catch
                        { }
                    }
                }
                else
                {
                    cEvent = new CalendarEvent(item.GlobalAppointmentID, item.Start, item.End, item.Location, item.Subject, item.Body);
                }

                if (cEvent != null)
                {
                    events.Add(cEvent);
                }
            }

            return(events);
        }
コード例 #9
0
 static void Main(string[] args)
 {
     Microsoft.Office.Interop.Outlook.Application myApp         = new Microsoft.Office.Interop.Outlook.Application();
     Microsoft.Office.Interop.Outlook.NameSpace   mapiNameSpace = myApp.GetNamespace("MAPI");
     Microsoft.Office.Interop.Outlook.MAPIFolder  myContacts    = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
     mapiNameSpace.Logon(null, null, false, false);//"*****@*****.**""14March96kr#"
     mapiNameSpace.Logon(ConfigurationSettings.AppSettings["MailId"], ConfigurationSettings.AppSettings["Password"], Missing.Value, true);
     Microsoft.Office.Interop.Outlook.Items myItems = myContacts.Items;
     myInbox    = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
     destFolder = myInbox.Folders["MaliciousAttachments"];
     Microsoft.Office.Interop.Outlook.Items    inboxItems = myInbox.Items;
     Microsoft.Office.Interop.Outlook.Explorer myexp      = myInbox.GetExplorer(false);
     mapiNameSpace.Logon("Profile", Missing.Value, false, true);
     new Program().readingUnReadMailsAsync(inboxItems);
 }
コード例 #10
0
        private void btnRead_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Outlook.Application myApp         = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   mapiNameSpace = myApp.GetNamespace("MAPI");
            Microsoft.Office.Interop.Outlook.MAPIFolder  myInbox       = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

            Microsoft.Office.Interop.Outlook.MAPIFolder oPublicFolder = myInbox.Parent;

            cmbOutlookFolders.Items.Clear();

            foreach (Microsoft.Office.Interop.Outlook.MAPIFolder folder in oPublicFolder.Folders)
            {
                EnumerateFolders(folder);
            }

            cmbOutlookFolders.DisplayMember = "Value";
            cmbOutlookFolders.ValueMember   = "Key";
        }
コード例 #11
0
ファイル: Default.aspx.cs プロジェクト: javitolin/MeetApp
        protected void outlookButton_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Outlook.Application oApp                 = null;
            Microsoft.Office.Interop.Outlook.NameSpace   mapiNamespace        = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder  CalendarFolder       = null;
            Microsoft.Office.Interop.Outlook.Items       outlookCalendarItems = null;

            oApp                 = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace        = oApp.GetNamespace("MAPI");;
            CalendarFolder       = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
            outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.IncludeRecurrences = true;
            allCalendarItemsText.Text = "";
            foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
            {
                allCalendarItemsText.Text += item.Subject + " -> " + item.Start.ToLongDateString();
            }
        }
コード例 #12
0
ファイル: main.cs プロジェクト: staherianYMCA/test
        public static void GetAllTaskItems()
        {
            Microsoft.Office.Interop.Outlook.Application oApp                 = null;
            Microsoft.Office.Interop.Outlook.NameSpace   mapiNamespace        = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder  CalendarFolder       = null;
            Microsoft.Office.Interop.Outlook.Items       outlookCalendarItems = null;

            oApp          = new Microsoft.Office.Interop.Outlook.Application();
            mapiNamespace = oApp.GetNamespace("MAPI");
            ;
            CalendarFolder =
                mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderTasks);
            outlookCalendarItems = CalendarFolder.Items;
            outlookCalendarItems.IncludeRecurrences = true;

            foreach (Microsoft.Office.Interop.Outlook.TaskItem item in outlookCalendarItems)
            {
                if (item.IsRecurring)
                {
                    //Microsoft.Office.Interop.Outlook.RecurrencePattern rp = item.GetRecurrencePattern();
                    //DateTime first = new DateTime(2008, 8, 31, item.Start.Hour, item.Start.Minute, 0);
                    //DateTime last = new DateTime(2008, 10, 1);
                    //Microsoft.Office.Interop.Outlook.AppointmentItem recur = null;



                    //for (DateTime cur = first; cur <= last; cur = cur.AddDays(1))
                    //{
                    //    try
                    //    {
                    //        recur = rp.GetOccurrence(cur);
                    //        Console.WriteLine(recur.Subject + " -> " + cur.ToLongDateString());
                    //    }
                    //    catch
                    //    {
                    //    }
                    //}
                }
                else
                {
                    Console.WriteLine(item.Subject + " -> " /* + item.Start.ToLongDateString()*/);
                }
            }
        }
コード例 #13
0
 public Outlook()
 {
     _ns    = _application.Session;
     _inbox = _ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
     _items = _inbox.Items;
     foreach (var item in _items)
     {
         string subject = string.Empty;
         var    mail    = item as Microsoft.Office.Interop.Outlook.MailItem;
         if (mail != null)
         {
             var subject = mail.Subject;
         }
         else
         {
             Debug.WriteLine("Item is not a MailItem");
         }
     }
 }
コード例 #14
0
        private void InitOutlookService()
        {
            if (!ifAlreadyInit)
            {
                oApp          = new Microsoft.Office.Interop.Outlook.Application();
                mapiNamespace = oApp.GetNamespace("MAPI");
                ;
                calendarFolder =
                    mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                outlookCalendarItems = calendarFolder.Items;

                outlookCalendarItems.Sort("[Start]");
                outlookCalendarItems.IncludeRecurrences = true;

                string s1           = GetDateInString(minTime);
                string s2           = GetDateInString(maxTime);
                var    filterString = "[Start] >= '" + s1 + "' AND [End] < '" + s2 + "'";
                outlookCalendarItems = outlookCalendarItems.Restrict(filterString);
                ifAlreadyInit        = true;
            }
        }
コード例 #15
0
ファイル: MainForm.cs プロジェクト: mdobro1/AI_Article_2
        public MainForm()
        {
            InitializeComponent();

            this.client = new ModeratorClient(Properties.Settings.Default.ContentModerator_SubscriptionKey);

            webBody.ScriptErrorsSuppressed = true;

            outlookApp       = new Microsoft.Office.Interop.Outlook.Application();
            outlookNamespace = outlookApp.GetNamespace("MAPI");
            accounts         = outlookApp.Session.Accounts;

            foreach (Microsoft.Office.Interop.Outlook.Account account in accounts)
            {
                toolStripComboBox_Accounts.Items.Add(account.DisplayName);
            }

            if (accountsExist())
            {
                toolStripComboBox_Accounts.SelectedIndex = 0;
            }
        }
コード例 #16
0
ファイル: Correo.cs プロジェクト: Kraker23/Utilities
        /// <summary>
        /// para enviar correos desde la cuenta del outlook instalada en tu ordinador
        /// </summary>
        /// <param name="mailDirection"> el destino del correo </param>
        /// <param name="cc">el cc del correo </param>
        /// <param name="cco">el cco del correo </param>
        /// <param name="mailSubject"> el asunto del correo </param>
        /// <param name="mailContent">el contenido del correo </param>
        /// <param name="adjuntos">los archivos adjutnos del correo </param>
        public string sendMail(string mailDirection, string cc, string cco, string mailSubject, string mailContent, List <string> adjuntos)
        {
            try
            {
                var oApp = new Microsoft.Office.Interop.Outlook.Application();

                Microsoft.Office.Interop.Outlook.NameSpace ns = oApp.GetNamespace("MAPI");
                var f = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);

                System.Threading.Thread.Sleep(1000);

                var mailItem = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                mailItem.Subject  = mailSubject;
                mailItem.HTMLBody = mailContent;
                mailItem.To       = mailDirection;
                mailItem.CC       = cc;
                mailItem.BCC      = cco;

                if (adjuntos != null && adjuntos.Count() > 0)
                {
                    foreach (string adj in adjuntos)
                    {
                        mailItem.Attachments.Add(adj);
                    }
                }

                mailItem.Send();
                return(string.Empty);
            }
            catch (Exception ex)
            {
                //MessageBox.Show(ex.Message);

                return(ex.Message);
            }
        }
コード例 #17
0
        private void btnLoadMessages_Click(object sender, EventArgs e)
        {
            Microsoft.Office.Interop.Outlook.Application myApp         = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   mapiNameSpace = myApp.GetNamespace("MAPI");

            KeyValuePair <string, string> selectedItem = (KeyValuePair <string, string>)cmbOutlookFolders.SelectedItem;

            Microsoft.Office.Interop.Outlook.MailItem mail01 = myApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Microsoft.Office.Interop.Outlook.MailItem;
            Microsoft.Office.Interop.Outlook.MailItem mail02 = myApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Microsoft.Office.Interop.Outlook.MailItem;

            mail01.Subject = "Move Deliverable Between TOWs Errors";
            mail01.Body    = "Hello Laura," + Environment.NewLine + Environment.NewLine +
                             "Attached are this week’s emails." + Environment.NewLine + Environment.NewLine +
                             "Thanks, Keith";

            mail02.Subject = "WorkOrders with No Deliverable";
            mail02.Body    = "Hello Laura," + Environment.NewLine + Environment.NewLine +
                             "Attached are this week’s emails." + Environment.NewLine + Environment.NewLine +
                             "Thanks, Keith";

            Microsoft.Office.Interop.Outlook.AddressEntry currentUser = myApp.Session.CurrentUser.AddressEntry;
            Microsoft.Office.Interop.Outlook.ExchangeUser manager     = currentUser.GetExchangeUser().GetExchangeUserManager();
            // Add recipient using display name, alias, or smtp address
            //mail.Recipients.Add(manager.PrimarySmtpAddress);
            mail01.Recipients.ResolveAll();
            mail02.Recipients.ResolveAll();

            Microsoft.Office.Interop.Outlook.MAPIFolder myInbox = mapiNameSpace.GetFolderFromID(selectedItem.Key);
            //cmbOutlookFolders.SelectedItem.ToString());// GetDefaultFolder(Microsoft.Office.Interop.Outlook.O.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            int total = myInbox.Items.Count, count = 0, xytCount = 0, unread = 0;

            if (total > 0)
            {
                foreach (Microsoft.Office.Interop.Outlook.MailItem item in myInbox.Items)
                {
                    count++;
                    unread++;
                    ListViewItem listitem = new ListViewItem(new[]
                    {
                        item.ReceivedTime.ToString(), item.SenderEmailAddress + "(" + item.Sender.Address.ToString() + ")", item.Subject, ((item.Attachments.Count > 0) ? "Yes" : "No"), item.EntryID.ToString()
                    });

                    if (item.Body.Contains("Attempt to move a Deliverable between TOWs"))
                    {
                        listitem.BackColor = Color.Plum;
                        xytCount++;

                        mail01.Attachments.Add(item, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                    }

                    if (item.Body.Contains("Failure Message Deliverable with Id"))
                    {
                        listitem.BackColor = Color.GreenYellow;
                        xytCount++;

                        mail02.Attachments.Add(item, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, Type.Missing, Type.Missing);
                    }

                    lstMsg.Items.Add(listitem);
                }

                lblEmailCount.Text = string.Format("Total Emails: {0}, Emails Need Attention: {1}, Unread: {2} ", total, xytCount, unread);
            }

            mail01.Save();
            mail02.Save();
        }
コード例 #18
0
        public void read()
        {
            Microsoft.Office.Interop.Outlook.Application outlook = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace   ns      = outlook.GetNamespace("Mapi");
            object _missing = Type.Missing;

            ns.Logon(_missing, _missing, false, true);
            Microsoft.Office.Interop.Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            string foldername = inbox.Name;
            int    iMailCount = inbox.Items.Count;

            TraceService("Inside read method");

            for (int iCount = 1; iCount <= iMailCount; iCount++)
            {
                Object mail1 = inbox.Items[iCount];
                if (((mail1 as Microsoft.Office.Interop.Outlook.MailItem) != null) && ((mail1 as Microsoft.Office.Interop.Outlook.MailItem).UnRead == true))
                {
                    TraceService("Inside unread mail");
                    Microsoft.Office.Interop.Outlook.MailItem mail = (Microsoft.Office.Interop.Outlook.MailItem)inbox.Items[iCount];
                    SqlConnection con;
                    string        connection = @"server=CSM-DEV\SQL2008;database=TerexBest;uid=sa;pwd=rimc@123";
                    TraceService("Connection with database done1");
                    con = new SqlConnection(connection);
                    SqlCommand cmd;
                    cmd = new SqlCommand();
                    con.Open();

                    cmd.Connection = con;
                    TraceService("Connection assigned to sql command");

                    string subject = mail.Subject.ToString();
                    TraceService("mail subject written" + subject);
                    string body = mail.Body.ToString();
                    cmd.Parameters.Add("@subject", SqlDbType.NVarChar).Value = subject;

                    TraceService(subject); //writing subject

                    cmd.Parameters.Add("@body", SqlDbType.NVarChar).Value = body;

                    TraceService(body); //writing subject

                    cmd.Parameters.Add("@recievedtime", SqlDbType.DateTime).Value = mail.ReceivedTime;

                    TraceService(mail.ReceivedTime.ToString()); //writing subject

                    cmd.Parameters.Add("@mailfrom", SqlDbType.NVarChar).Value = mail.SenderEmailAddress;

                    TraceService(mail.SenderEmailAddress); //writing subject
                    TraceService("Before Inventory saved");

                    cmd.CommandText = "insert into storemail(subject,body,createddatetime,mailfrom,isActive) values(@subject,@body,@recievedtime,@mailfrom,1)";
                    TraceService("Inventory saved");
                    try
                    {
                        cmd.ExecuteNonQuery();
                        mail.Delete();
                        iMailCount = iMailCount - 1;
                    }
                    catch (SqlException ex)
                    {
                        ex.ToString();
                    }
                    con.Close();
                    cmd.Dispose();
                    con.Dispose();
                }
            }

            GC.Collect();
            inbox   = null;
            ns      = null;
            outlook = null;
        }
コード例 #19
0
        public static void UpdateCache(bool resetException = false)
        {
            if (resetException)
            {
                OutlookException = null;
            }

            if (OutlookException != null)
            {
                return;
            }

            var events = new List <OutlookItem>();

            Microsoft.Office.Interop.Outlook.Application oApp                 = null;
            Microsoft.Office.Interop.Outlook.NameSpace   mapiNamespace        = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder  calendarFolder       = null;
            Microsoft.Office.Interop.Outlook.Items       outlookCalendarItems = null;

            try
            {
                oApp                 = new Microsoft.Office.Interop.Outlook.Application();
                mapiNamespace        = oApp.GetNamespace("MAPI");
                calendarFolder       = mapiNamespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
                outlookCalendarItems = calendarFolder.Items;
                outlookCalendarItems.Sort("[Start]");
                outlookCalendarItems.IncludeRecurrences = true;
                //var filter = String.Format("[Start] >= \"{0}\" and [Start] <= \"{1}\"", DateTime.Today, DateTime.Today.AddDays(1));
                //outlookCalendarItems = outlookCalendarItems.Find(filter);

                foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in outlookCalendarItems)
                {
                    if (item.Start >= CacheRangeStart)
                    {
                        if (item.Start.Date > CacheRangeEnd)
                        {
                            break;
                        }

                        var parsed = LyncMeeting.ParseEmail(item.Body ?? string.Empty, item.Subject);
                        events.Add(new OutlookItem()
                        {
                            Start              = item.Start,
                            End                = item.End,
                            Subject            = item.Subject,
                            LyncMeeting        = parsed,
                            OutlookAppointment = item
                        });
                    }
                }

                events = events.OrderBy(e => e.Start).ToList();
                lock (Lock)
                {
                    _cache = events;
                    _cacheLastUpdateTime = DateTime.Now;
                }
            }
            catch (COMException e)
            {
                OutlookException = e;
            }
            finally
            {
                Marshal.ReleaseComObject(oApp);
            }
        }
コード例 #20
0
ファイル: Metier.cs プロジェクト: jraillard/Ken-go-Software
        public void CreateNewDistributionList(string[] tabAdresse)
        {
            Microsoft.Office.Interop.Outlook._Application OutlookApp       = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.NameSpace    ns               = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder   folderContacts   = null;
            Microsoft.Office.Interop.Outlook.Items        contactItems     = null;
            Microsoft.Office.Interop.Outlook.MailItem     mail             = null;
            Microsoft.Office.Interop.Outlook.Recipients   listRecipients   = null;
            Microsoft.Office.Interop.Outlook.DistListItem distributionList = null;
            try
            {
                string addresseToAdd;
                ns             = OutlookApp.GetNamespace("MAPI");
                folderContacts = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderContacts);
                contactItems   = folderContacts.Items;
                // create a new e-mail message to access the recipients collection
                mail           = contactItems.Add(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem) as Microsoft.Office.Interop.Outlook.MailItem;
                mail.To        = "";
                listRecipients = mail.Recipients;
                //création de la liste d'adresse
                foreach (string addresse in tabAdresse)
                {
                    if (addresse != null)
                    {
                        addresseToAdd = RemoveDiacritics(addresse);
                        listRecipients.Add(addresseToAdd);
                    }
                }

                if (!listRecipients.ResolveAll())
                {
                    System.Windows.Forms.MessageBox.Show("There are no such contact names. " +
                                                         "Please make sure that you have corresponding records in your address book",
                                                         "Add-in Express", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                // create a new distribution list item
                distributionList = contactItems.Add(Microsoft.Office.Interop.Outlook.OlItemType.olDistributionListItem)
                                   as Microsoft.Office.Interop.Outlook.DistListItem;
                distributionList.DLName = "List judo";
                distributionList.AddMembers(listRecipients);
                distributionList.Display(true);
            }
            catch (Exception e)
            {
                throw new Exception("Erreur Metier.cs/CreateNewDistributionList():\r\n" + e.Message, e);
            }
            finally
            {
                if (distributionList != null)
                {
                    Marshal.ReleaseComObject(distributionList);
                }
                if (listRecipients != null)
                {
                    Marshal.ReleaseComObject(listRecipients);
                }
                if (mail != null)
                {
                    mail.Delete();
                    Marshal.ReleaseComObject(mail);
                }
                if (contactItems != null)
                {
                    Marshal.ReleaseComObject(contactItems);
                }
                if (folderContacts != null)
                {
                    Marshal.ReleaseComObject(folderContacts);
                }
                if (ns != null)
                {
                    Marshal.ReleaseComObject(ns);
                }
            }
        }
コード例 #21
0
ファイル: OutboxMonitor.cs プロジェクト: killbug2004/WSProf
        public void Dispose()
        {
            _disposing = true;

            ClosePendingSubmitWaitHandles();

            if (_items != null)
            {
                _items.ItemAdd -= Items_ItemAdd;
                _items = null;
            }

            if (_outbox != null)
            {
                ((IDisposable)_outbox).Dispose();
                _outbox = null;
            }

            if (_ns != null)
            {
                ((IDisposable)_ns).Dispose();
                _ns = null;
            }

            if (_application != null)
            {
                ((IDisposable)_application).Dispose();
                _application = null;
            }
        }