Esempio n. 1
0
 /// <summary>
 /// Creates a new item
 /// </summary>
 public ItemType Create <ItemType>()
     where ItemType : IItem
 {
     using (ComRelease com = new ComRelease())
     {
         NSOutlook.Items items = com.Add(_item.Items);
         object          item  = items.Add(Mapping.OutlookItemType <ItemType>());
         return(Mapping.Wrap <ItemType>(item));
     }
 }
Esempio n. 2
0
        static void VagtplanOutlook(string pSlutDT)
        {
            DateTime    SlutDT      = DateTime.Parse(pSlutDT);
            clsTemplate objTemplate = new clsTemplate();

            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace   oNS  = oApp.GetNamespace("mapi");
            oNS.Logon(Missing.Value, Missing.Value, true, true);
            Outlook.MAPIFolder oCalendar = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
            Outlook.Items      oItems    = oCalendar.Items;
            string             dayfilter = "[Start] >= '" + DateTime.Today.Date.ToString("g") + "' AND [End] < '" + SlutDT.Date.ToString("g") + "'";
            string             subjectfilter;

            if (oApp.Session.DefaultStore.IsInstantSearchEnabled)
            {
                subjectfilter = "@SQL=\"urn:schemas:httpmail:subject\" ci_startswith '" + objTemplate.Tekst + "'";
            }
            else
            {
                subjectfilter = "@SQL=\"urn:schemas:httpmail:subject\" like '%" + objTemplate.Tekst + "%'";
            }

            Outlook.Items oDagItems = oItems.Restrict(dayfilter).Restrict(subjectfilter);
            for (int i = oDagItems.Count; i > 0; i--)
            {
                oDagItems[i].Delete();
            }

            for (DateTime dt = DateTime.Today; dt.Date <= SlutDT.Date; dt = dt.AddDays(1).Date)
            {
                recTemplate rec = objTemplate.getDag(dt);

                if (!rec.Fri)
                {
                    Outlook.AppointmentItem oAppt = (Outlook.AppointmentItem)oItems.Add(Outlook.OlItemType.olAppointmentItem);
                    oAppt.Subject     = objTemplate.Tekst; // set the subject
                    oAppt.Start       = dt.Date.Add((TimeSpan)rec.Start);
                    oAppt.End         = dt.Date.Add((TimeSpan)rec.S**t);
                    oAppt.ReminderSet = false;                                   // Set the reminder
                    oAppt.Importance  = Outlook.OlImportance.olImportanceNormal; // appointment importance
                    oAppt.BusyStatus  = Outlook.OlBusyStatus.olBusy;
                    oAppt.Save();
                }
            }
        }
Esempio n. 3
0
        public bool AddNewContact(cls_Contact contact)
        {
            Outlook.MAPIFolder mAPIFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
            Outlook.Items      items      = mAPIFolder.Items;
            try
            {
                Outlook.ContactItem newContact = items.Add(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;

                newContact.Title                 = contact.PatientID;
                newContact.JobTitle              = contact.DiseaseName;
                newContact.FirstName             = contact.FirstName;
                newContact.LastName              = contact.LastName;
                newContact.MiddleName            = contact.FatherName;
                newContact.Suffix                = contact.SSID;
                newContact.HomeTelephoneNumber   = contact.Phone;
                newContact.MobileTelephoneNumber = contact.Mobile;
                newContact.Body          = contact.Notes;
                newContact.User1         = contact.Birthday;
                newContact.Email1Address = contact.Email;
                newContact.HomeAddress   = contact.Address;

                newContact.Save();
                contacts.Add(contact);

                if (mAPIFolder != null)
                {
                    Marshal.ReleaseComObject(mAPIFolder);
                }
                if (items != null)
                {
                    Marshal.ReleaseComObject(items);
                }
                if (newContact != null)
                {
                    Marshal.ReleaseComObject(newContact);
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Adds an event to another calendar in the outlook application. Calendar must be present in
        /// the shared folder of outlook. Creates an event object in that folder and then utilizes
        /// common library to add the attributes
        /// </summary>
        /// <param name="subject">Title of the event to add</param>
        /// <param name="startDate">The date of the specific event M/d/yyyy hh:mm:ss tt</param>
        /// <param name="recurrenceType">Recurrence type: daily, weekly, monthly, yearly</param>
        /// <param name="endDate">End date for the recurrence</param>
        /// <param name="duration">Duration of the event</param>
        /// <param name="otherCalendar">Name of the other calendar</param>
        /// <param name="recipients">Array of recipeints to add to the event</param>
        public void AddEventToOtherCalendar(string subject, string startDate, string recurrenceType, string endDate, string duration, string otherCalendar, string[] recipients)
        {
            string methodTag = "AddEventToOtherCalendar";

            LogWriter.WriteInfo(TAG, methodTag, "Starting: " + methodTag + " in " + TAG);

            Outlook.Application     app           = null;
            Outlook.AppointmentItem agendaMeeting = null;
            Outlook.NameSpace       NS            = null;
            Outlook.MAPIFolder      objFolder     = null;
            Outlook.MailItem        objTemp       = null;
            Outlook.Recipient       objRecip      = null;
            Outlook.Items           objItems      = null;

            app      = new Outlook.Application();
            NS       = app.GetNamespace("MAPI");
            objTemp  = app.CreateItem(Outlook.OlItemType.olMailItem);
            objRecip = objTemp.Recipients.Add(otherCalendar);
            objTemp  = null;
            objRecip.Resolve();

            if (objRecip.Resolved)
            {
                objFolder     = NS.GetSharedDefaultFolder(objRecip, Outlook.OlDefaultFolders.olFolderCalendar);
                objItems      = objFolder.Items;
                agendaMeeting = objItems.Add();

                LogWriter.WriteInfo(TAG, methodTag, "Adding details to event item");
                agendaMeeting = CommonLibrary.CreateEvent(agendaMeeting, subject, startDate, recurrenceType, endDate, duration, recipients);

                LogWriter.WriteInfo(TAG, methodTag, "Sending event");
                agendaMeeting.Send();
                LogWriter.WriteInfo(TAG, methodTag, subject + " sucessfully sent");
            }
            else
            {
                LogWriter.WriteWarning(TAG, methodTag, "Recipient object was not sucessfully resolved");
                throw new NullReferenceException();
            }

            return;
        }
Esempio n. 5
0
        /// <summary>
        /// Event handler for CGrabber application new mail arrived event.
        /// </summary>
        /// <param name="entryIdCollection">Entry Id collection.</param>
        private void CGrabberApplicationNewMailEx(string entryIdCollection)
        {
            var namespaceitem = this.cgrabberApplication.GetNamespace("MAPI");
            var stores        = this.cgrabberApplication.Session.Stores;

            foreach (var folder in from Outlook.Store store in stores select store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox))
            {
                try
                {
                    var mailItem = (Outlook.MailItem)namespaceitem.GetItemFromID(entryIdCollection, folder.StoreID);
                    if (null == mailItem)
                    {
                        return;
                    }

                    var searchResult = false;
                    if (mailItem.Body != null)
                    {
                        searchResult = SearchKeywords.Any(keyword => mailItem.Body.IndexOf(keyword) != -1);
                    }

                    var searchResultHtmlBody = false;
                    if (mailItem.HTMLBody != null)
                    {
                        searchResultHtmlBody = SearchKeywords.Any(keyword => mailItem.HTMLBody.IndexOf(keyword) != -1);
                    }

                    var subjectSearchResult = false;
                    if (mailItem.Subject != null)
                    {
                        subjectSearchResult = SearchKeywords.Any(keyword => mailItem.Subject.IndexOf(keyword) != -1);
                    }

                    if (!searchResult && !searchResultHtmlBody && !subjectSearchResult)
                    {
                        return;
                    }

                    Outlook.MAPIFolder  contactsFolder = null;
                    Outlook.Items       items          = null;
                    Outlook.ContactItem contact        = null;
                    try
                    {
                        contactsFolder = this.cgrabberApplication.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
                        items          = contactsFolder.Items;
                        var filter = "[Email1Address] = '" + mailItem.SenderEmailAddress + "'";
                        Outlook.ContactItem existingContact = null;
                        existingContact = items.Find(filter) as Outlook.ContactItem;
                        if (existingContact != null)
                        {
                            return;
                        }
                        else
                        {
                            filter          = "[Email2Address] = '" + mailItem.SenderEmailAddress + "'";
                            existingContact = items.Find(filter) as Outlook.ContactItem;
                            if (existingContact != null)
                            {
                                return;
                            }
                            else
                            {
                                filter          = "[Email3Address] = '" + mailItem.SenderEmailAddress + "'";
                                existingContact = items.Find(filter) as Outlook.ContactItem;
                                if (existingContact != null)
                                {
                                    return;
                                }
                                else
                                {
                                    contact = items.Add(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
                                    if (null == contact)
                                    {
                                        return;
                                    }

                                    contact.Email1Address     = mailItem.SenderEmailAddress;
                                    contact.Email1DisplayName = mailItem.SenderName;
                                    contact.Save();
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        if (contact != null)
                        {
                            Marshal.ReleaseComObject(contact);
                        }
                        if (items != null)
                        {
                            Marshal.ReleaseComObject(items);
                        }
                        if (contactsFolder != null)
                        {
                            Marshal.ReleaseComObject(contactsFolder);
                        }
                    }
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }
Esempio n. 6
0
        private void ButtonAddContactJunk_Click(object sender, RibbonControlEventArgs e)
        {
            if (Globals.ThisAddIn.Application.ActiveExplorer().Selection.Count > 0)
            {
                Object selectedObject = Globals.ThisAddIn.Application.ActiveExplorer().Selection[1];
                if (selectedObject is Outlook.MailItem email)
                {
                    if (email is object)
                    {
                        Outlook.MAPIFolder  contactsFolder = null;
                        Outlook.Items       items          = null;
                        Outlook.ContactItem contact        = null;
                        try
                        {
                            InTouch.ShowInTouchSettings = true;
                            contactsFolder = Globals.ThisAddIn.Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).Folders["Junk Contacts"];
                            items          = contactsFolder.Items;
                            contact        = items.Add(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;

                            Clipboard.SetDataObject(email.Sender.Name);

                            contact.FullName      = email.Sender.Name;
                            contact.Email1Address = email.Sender.Address;

                            string data;
                            contact.UserProperties.Add("InTouchContact", Outlook.OlUserPropertyType.olText);
                            data  = "|";
                            data += "|";
                            data += "3|";
                            data += "3|";
                            data += "0|";
                            data += "True|";
                            contact.UserProperties["InTouchContact"].Value = data;

                            contact.Save();
                            contact.Display(true);

                            lastEntryID = "";
                            Parallel.Invoke(() => { CheckEmailSender(); });
                        }
                        catch (Exception ex)
                        {
                            Log.Error(ex);
                            InTouch.ShowInTouchSettings = false;
                        }
                        finally
                        {
                            if (contact != null)
                            {
                                Marshal.ReleaseComObject(contact);
                            }
                            if (items != null)
                            {
                                Marshal.ReleaseComObject(items);
                            }
                            if (contactsFolder != null)
                            {
                                Marshal.ReleaseComObject(contactsFolder);
                            }
                        }
                    }
                    if (email is object)
                    {
                        Marshal.ReleaseComObject(email);
                    }
                }
                if (selectedObject is object)
                {
                    Marshal.ReleaseComObject(selectedObject);
                }
            }
        }
Esempio n. 7
0
        public bool UpdateAppointment(cls_Appointment oldAppointment, cls_Appointment newAppointment)
        {
            try
            {
                Outlook.MAPIFolder mAPIFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
                Outlook.Items      items      = mAPIFolder.Items;
                items.Sort("[Start]");

                ApplicationConfigManagement acm = new ApplicationConfigManagement();
                string dateCultureFormat        = acm.ReadSetting("DateCultureFormat").ToLower();
                string filterStr = "";
                if (dateCultureFormat == "d")
                {
                    CultureInfo culture  = new CultureInfo("EN-en");
                    string      StartStr = oldAppointment.StartDateTime.ToString("dd/MM/yyyy", culture);
                    string      EndStr   = oldAppointment.StartDateTime.AddDays(1).ToString("dd/MM/yyyy", culture);
                    filterStr = "[Start] >= '" + StartStr + "' AND [End] < '" + EndStr + "'";
                }
                else if (dateCultureFormat == "g")
                {
                    filterStr = "[Start]='" + oldAppointment.StartDateTime.ToString("g") + "'";
                }
                //Outlook.AppointmentItem appointment = items.Find(filterStr);
                Outlook.Items appointments = items.Restrict(filterStr);
                foreach (Outlook.AppointmentItem appointment in appointments)
                {
                    if (appointment != null && appointment.Subject == oldAppointment.Subject)
                    {
                        appointment.Subject  = newAppointment.Subject;
                        appointment.Location = newAppointment.Paid;
                        appointment.Save();

                        oldAppointment.Subject = newAppointment.Subject;
                        oldAppointment.Paid    = newAppointment.Paid;

                        if (mAPIFolder != null)
                        {
                            Marshal.ReleaseComObject(mAPIFolder);
                        }
                        if (items != null)
                        {
                            Marshal.ReleaseComObject(items);
                        }
                        if (appointment != null)
                        {
                            Marshal.ReleaseComObject(appointment);
                        }
                        return(true);
                    }
                    else
                    {
                    }
                }
                Outlook.AppointmentItem AddnewAppointment = items.Add(Outlook.OlItemType.olAppointmentItem) as Outlook.AppointmentItem;
                AddnewAppointment.Start    = newAppointment.StartDateTime;
                AddnewAppointment.End      = newAppointment.EndDateTime;
                AddnewAppointment.Subject  = newAppointment.Subject;
                AddnewAppointment.Location = newAppointment.Paid;
                AddnewAppointment.Save();
                oldAppointment.Subject = newAppointment.Subject;
                oldAppointment.Paid    = newAppointment.Paid;

                if (mAPIFolder != null)
                {
                    Marshal.ReleaseComObject(mAPIFolder);
                }
                if (items != null)
                {
                    Marshal.ReleaseComObject(items);
                }
                if (AddnewAppointment != null)
                {
                    Marshal.ReleaseComObject(AddnewAppointment);
                }

                return(true);
            }
            catch (Exception err)
            {
                logger.ErrorLog("Update Conact Info : " + err.Message);
                return(false);
            }
            return(false);
        }