コード例 #1
0
ファイル: Ribbon3.cs プロジェクト: darren4ten/QuickOoOAddin
        private void BuildEmail(MailType mailType)
        {
            Microsoft.Office.Interop.Outlook.AppointmentItem agendaMeeting =
                _app.Application.CreateItem(Outlook.OlItemType.olAppointmentItem);
            agendaMeeting.MeetingStatus =
                Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
            agendaMeeting.Location    = "";
            agendaMeeting.Importance  = Outlook.OlImportance.olImportanceLow;
            agendaMeeting.AllDayEvent = true;
            var user = GetCurrentUserInfo();

            if (mailType == MailType.OoO)
            {
                agendaMeeting.Subject = GetHandledSubject(Settings1.Default.txtSubject_OoO, user.Name);
                //agendaMeeting.Body = Settings1.Default.txtBody_OoO;
                SetupRecipients(agendaMeeting.Recipients, Settings1.Default.txtReceivers_OoO, Settings1.Default.txtReceiversRequired_OoO);
                SetupBody(agendaMeeting, Settings1.Default.txtBody_OoO);
            }
            else
            {
                agendaMeeting.Subject = GetHandledSubject(Settings1.Default.txtSubject_WFH, user.Name);
                //agendaMeeting.Body = Settings1.Default.txtBody_WFH;
                SetupRecipients(agendaMeeting.Recipients, Settings1.Default.txtReceivers_WFH, Settings1.Default.txtReceiversRequired_WFH);
                SetupBody(agendaMeeting, Settings1.Default.txtBody_WFH);
            }

            agendaMeeting.BusyStatus = Outlook.OlBusyStatus.olFree;

            agendaMeeting.Display(false);
        }
コード例 #2
0
        protected void populateAddressListFromOutlook()
        {
            DateTime startDate, endDate;

            endDate   = DateTime.Today;
            startDate = endDate.AddDays(-30);

            // app = new Microsoft.Office.Interop.Outlook.Application(); - this line will create problem with Outlook 2013 sometimes
            app = this.Application;
            //}
            ns = app.GetNamespace("MAPI");


            calendar = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

            String StringToCheck = "";

            StringToCheck = "[Start] >= " + "\"" + startDate.ToString().Substring(0, startDate.ToString().IndexOf(" ")) + "\""
                            + " AND [End] <= \"" + endDate.ToString().Substring(0, endDate.ToString().IndexOf(" ")) + "\"";


            Microsoft.Office.Interop.Outlook.Items oItems = (Microsoft.Office.Interop.Outlook.Items)calendar.Items;
            Microsoft.Office.Interop.Outlook.Items restricted;

            oItems.Sort("[Start]", false);
            oItems.IncludeRecurrences = true;

            restricted = oItems.Restrict(StringToCheck);
            restricted.Sort("[Start]", false);

            restricted.IncludeRecurrences = true;
            Microsoft.Office.Interop.Outlook.AppointmentItem oAppt = (Microsoft.Office.Interop.Outlook.AppointmentItem)restricted.GetFirst();

            Dictionary <String, String> comboDict = new Dictionary <string, string>();

            comboDict.Add("ALL", "ALL");

            //Loop through each appointment item to find out the unique recipient list and add to the combo box
            while (oAppt != null)
            {
                oAppt = (Microsoft.Office.Interop.Outlook.AppointmentItem)restricted.GetNext();

                if (oAppt != null)
                {
                    foreach (Microsoft.Office.Interop.Outlook.Recipient rcp in oAppt.Recipients)
                    {
                        //Display the email id in bracket along with the name in case the name rcp.Name does not contain the email address
                        //This will help in situtation where the the same recipient with multiple emails address need to be distinguised
                        String recpDisplayString = rcp.Name.IndexOf("@") < 0 ? rcp.Name + "(" + rcp.Address + ")" : rcp.Name;

                        if (!comboDict.ContainsKey(recpDisplayString))
                        {
                            comboDict.Add(recpDisplayString, recpDisplayString);
                            if (recpDisplayString != null && !emailNameMappingDict.ContainsKey(recpDisplayString))
                            {
                                emailNameMappingDict.Add(recpDisplayString, rcp.Address != null ? rcp.Address : rcp.Name);
                            }
                            if (rcp.Name != null && !MOM_Form.autoCompleteList.Contains(recpDisplayString))
                            {
                                MOM_Form.autoCompleteList.Add(recpDisplayString);
                            }
                        }
                    }
                }
            }

            //listBox_AddrList.DataSource = new BindingSource(comboDict, null);
            //listBox_AddrList.DisplayMember = "Value";
            //listBox_AddrList.ValueMember = "Key";
            //listBox_AddrList.SelectedValue = "ALL";

            populateAutoCompleteList(startDate, endDate);
        }