Exemple #1
0
        private void appointmentsInRange()
        {
            Microsoft.Office.Interop.Outlook.Application a         = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.Folder      calFolder = a.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar) as Microsoft.Office.Interop.Outlook.Folder;
            DateTime start = DateTime.Now;
            DateTime end   = start.AddDays(1);

            Microsoft.Office.Interop.Outlook.Items rangeAppts = GetAppointmentsInRange(calFolder, start, end);
            if (rangeAppts != null)
            {
                int size = 0;
                foreach (Microsoft.Office.Interop.Outlook.AppointmentItem appt in rangeAppts)
                {
                    size++;
                }
                ss.SpeakAsync("You have " + size + " items on your calendar today");
                foreach (Microsoft.Office.Interop.Outlook.AppointmentItem appt in rangeAppts)
                {
                    setLabel(appt.Subject + " starts at " + appt.Start.ToString());
                    ss.SpeakAsync(appt.Subject + " starts at " + appt.Start.ToString());
                    opt += appt.Subject + " " + appt.Start.ToString() + "#";
                }
            }
            else
            {
                ss.SpeakAsync("Sorry i could not find anything! Try again later");
            }
        }
Exemple #2
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;
        }
Exemple #3
0
        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;
            }
        }
Exemple #4
0
    private Microsoft.Office.Interop.Outlook.Items GetAppointmentsInRange(
        Microsoft.Office.Interop.Outlook.Folder folder, DateTime startTime, DateTime endTime)
    {
        string filter = "[Start] >= '" + startTime.ToString("g") + "' AND [End] <= '" + endTime.ToString("g") + "'";

        //Response.Write(filter);
        try
        {
            Microsoft.Office.Interop.Outlook.Items calItems = folder.Items;
            calItems.IncludeRecurrences = true;
            calItems.Sort("[Start]", Type.Missing);
            Microsoft.Office.Interop.Outlook.Items restrictItems = calItems.Restrict(filter);
            if (restrictItems.Count > 0)
            {
                return(restrictItems);
            }
            else
            {
                return(null);
            }
        }
        catch
        {
            return(null);
        }
    }
        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);
            }
        }
 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;
     }
 }
        /// <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);
        }
 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);
 }
Exemple #9
0
    private void DemoAppointmentsInRange()
    {
        Application a = new Application();

        Microsoft.Office.Interop.Outlook.Folder calFolder = a.Session.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar) as Microsoft.Office.Interop.Outlook.Folder;
        DateTime start = DateTime.Now;
        DateTime end   = start.AddDays(5);

        Microsoft.Office.Interop.Outlook.Items rangeAppts = GetAppointmentsInRange(calFolder, start, end);
        if (rangeAppts != null)
        {
            foreach (Microsoft.Office.Interop.Outlook.AppointmentItem appt in rangeAppts)
            {
                Response.Write("Subject: " + appt.Subject + " " + " Start: " + appt.Start.ToString() + " " + "End:" + appt.End.ToString() + "<br/>");
            }
        }
    }
Exemple #10
0
        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();
            }
        }
Exemple #11
0
        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()*/);
                }
            }
        }
 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");
         }
     }
 }
Exemple #13
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;
            }
        }
Exemple #14
0
        /// <summary>
        /// Metodo que descarga los archivos adjuntos de los correos
        /// no leidos de la cuenta de outlook
        /// </summary>
        public void bandejaEntradaOutlook()
        {
            Microsoft.Office.Interop.Outlook.Application app         = null;
            Microsoft.Office.Interop.Outlook._NameSpace  ns          = null;
            Microsoft.Office.Interop.Outlook.MAPIFolder  inboxFolder = null;
            Microsoft.Office.Interop.Outlook.MailItem    sinLeer;

            int p = 0, t = 0;

            while (!detenerHilo)
            {
                try
                {
                    app = new Microsoft.Office.Interop.Outlook.Application();

                    ns = app.GetNamespace("MAPI");
                    ns.Logon(null, null, false, false);

                    inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.
                                                      OlDefaultFolders.olFolderInbox);

                    ///Se obtiene la bandeja de entrada de la cuenta de correo
                    Microsoft.Office.Interop.Outlook.Items inboxItems = inboxFolder.Items;

                    t = inboxFolder.UnReadItemCount;

                    ///Se obtiene la bandeja de entrada de correos no leidos
                    inboxItems = inboxItems.Restrict("[unread] = true");

                    while (p < t)
                    {
                        if (p == 0)
                        {
                            ///Se obtiene el primer elemento de la bandeja de entrada
                            sinLeer = inboxItems.GetFirst();
                        }
                        else
                        {
                            ///Se obtiene el elemento siguiente de la bandeja de entrada
                            sinLeer = inboxItems.GetNext();
                        }

                        ///Se obtiene los archivos adjuntos del correo
                        Microsoft.Office.Interop.Outlook.Attachments adjuntos = sinLeer.Attachments;

                        foreach (Microsoft.Office.Interop.Outlook.Attachment archivo in adjuntos)
                        {
                            if (ValidarXmlSobre(archivo.FileName))
                            {
                                ///Se marca el correo como no leido
                                sinLeer.UnRead = false;

                                //Se descargar el archivo adjunto del correo
                                archivo.SaveAsFile(RutasCarpetas.RutaCarpetaBandejaEntrada + archivo.FileName);
                                string desde = sinLeer.Sender.ToString();

                                //Se sube el archivo al servidor FTP
                                FTP ftp = new FTP();
                                ftp.CargarArchivos(archivo.FileName, RutasCarpetas.RutaCarpetaBandejaEntrada, 3);

                                //Se guarda en la tabla de sobres Recibidos

                                respuestaSobre.GenerarXML(RutasCarpetas.RutaCarpetaBandejaEntrada, archivo.FileName, desde);
                            }
                            //Se comprueba que sea un ACK
                            else if (ValidarXmlACKSobre(archivo.FileName))
                            {
                                archivo.SaveAsFile(RutasCarpetas.RutaCarpetaBandejaEntrada);
                                sinLeer.UnRead = false;

                                SobreTransito         sobreTransito      = ObtenerSobreTransito(archivo.FileName, sinLeer.Sender.ToString());
                                ManteUdoSobreTransito manteSobreTransito = new ManteUdoSobreTransito();
                                manteSobreTransito.Almacenar(sobreTransito);
                            }
                        }
                        p = p + 1;
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    ns          = null;
                    app         = null;
                    inboxFolder = null;

                    Thread.Sleep(60000);
                }
            }
        }
        public void readingUnReadMailsAsync(Microsoft.Office.Interop.Outlook.Items inboxItems)
        {
            if (myInbox.Items.Count > 0)
            {
                Microsoft.Office.Interop.Outlook.Items items = myInbox.Items;
                inboxItems = inboxItems.Restrict("[UnRead] = true");
                Console.WriteLine(string.Format("Total Unread message {0}:", inboxItems.Count));
                int x = 0;

                foreach (Microsoft.Office.Interop.Outlook.MailItem item in inboxItems)
                {
                    var attachments = item.Attachments;
                    var urlhtml     = item.HTMLBody;

                    string Textbody = item.Body;
                    var    matches  = Regex.Matches(urlhtml, @"<a\shref=""(?<url>.*?)"">(?<text>.*?)</a>");
                    if (attachments.Count != 0)
                    {
                        new LogFile().Writelog("Unread Mail from your inbox :-");
                        ++x;
                        Console.WriteLine("{0} Unread Mail from your inbox", ++x);
                        new LogFile().Writelog("            x");
                        new LogFile().Writelog("from:-");
                        string SenderName = item.SenderName;
                        new LogFile().Writelog("SenderName");
                        string ReceiverName = item.ReceivedByName;
                        new LogFile().Writelog("ReceiverName");
                        string Subject = item.Subject;
                        new LogFile().Writelog("Subject");
                        Console.WriteLine(string.Format("from:-     {0}", item.SenderName));
                        Console.WriteLine(string.Format("To:-     {0}", item.ReceivedByName));
                        Console.WriteLine(string.Format("Subject:-     {0}", item.Subject));
                        // Console.WriteLine(string.Format("Message:-     {0}", item.Body));
                        for (int i = 1; i <= attachments.Count; i++)
                        {
                            new LogFile().Writelog("Attachments:-");
                            string Attachments = item.Attachments[i].FileName;
                            new LogFile().Writelog("Attachments");
                            file = Path.GetFullPath(item.Attachments[i].FileName);
                            new VirusChecking().processVirusTotal(file, item, ScanUrl, matches);
                        }
                    }
                    else if (matches.Count != 0)
                    {
                        foreach (Match url in matches)
                        {
                            ScanUrl = url.Groups["url"].Value;
                            new VirusChecking().processVirusTotal(file, item, ScanUrl, matches);
                        }
                    }
                    else
                    {
                        string   path     = @"C:\Users\10653836\Desktop\dll.txt";
                        string[] contents = File.ReadAllLines(path);
                        if (contents.Any(item.Subject.Contains))
                        {
                            new VirusChecking().MoveAttactment(item);
                        }
                    }
                }
            }
        }
        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);
            }
        }
Exemple #17
0
        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);
                }
            }
        }
Exemple #18
0
        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;
            }
        }