コード例 #1
0
        public static String SendFullDayAppointment(String fromAddress, String startDate, List <String> requiredAttendies, List <String> optionalAttendies, String subj, String body, List <String> attachments, String attachLocation)
        {
            Outlook.Application     application  = new Outlook.Application();
            Outlook.AppointmentItem oAppointment = (Outlook.AppointmentItem)application.CreateItem(Outlook.OlItemType.olAppointmentItem);

            oAppointment.Subject  = subj;
            oAppointment.Body     = body;
            oAppointment.Location = "Appointment location";

            // Set the start date
            oAppointment.Start = Convert.ToDateTime(startDate);

            oAppointment.AllDayEvent = true;

            // Set the reminder 15 minutes before start
            oAppointment.ReminderSet = true;
            oAppointment.ReminderMinutesBeforeStart = 15;

            //Setting the importance:
            //use OlImportance enum to set the importance to low, medium or high

            oAppointment.Importance = Outlook.OlImportance.olImportanceHigh;

            /* OlBusyStatus is enum with following values:
             * olBusy
             * olFree
             * olOutOfOffice
             * olTentative
             */
            oAppointment.BusyStatus    = Outlook.OlBusyStatus.olBusy;
            oAppointment.MeetingStatus = Outlook.OlMeetingStatus.olMeeting;

            if (requiredAttendies != null)
            {
                foreach (String toAddress in requiredAttendies)
                {
                    Outlook.Recipient recipient = oAppointment.Recipients.Add(toAddress);
                    recipient.Type = (int)Outlook.OlMeetingRecipientType.olRequired;
                }
            }

            if (optionalAttendies != null)
            {
                foreach (String optAddress in optionalAttendies)
                {
                    Outlook.Recipient optRecipient = oAppointment.Recipients.Add(optAddress);
                    optRecipient.Type = (int)Outlook.OlMeetingRecipientType.olOptional;
                }
            }

            //Outlook.Recipient organizer = oAppointment.Recipients.Add(fromAddress);
            //organizer.Type = (int)Outlook.OlMeetingRecipientType.olOrganizer;

            oAppointment.Recipients.ResolveAll();
            //String iCalUid = oAppointment.GlobalAppointmentID;

            if (!attachments.Count.Equals(0))
            {
                foreach (String attachName in attachments)
                {
                    String sSource      = attachLocation;
                    String sDisplayName = attachName;

                    int iPosition   = (int)oAppointment.Body.Length + 1;
                    int iAttachType = (int)Outlook.OlAttachmentType.olByValue;

                    oAppointment.Attachments.Add(sSource, iAttachType, iPosition, sDisplayName);
                }
            }

            // Save the appointment
            oAppointment.SaveAs(@"D:\Temp\Test.ics", Outlook.OlSaveAsType.olICal);

            //Outlook.Account acc = OutlookManage.GetAccount(application, fromAddress);
            //oAppointment.SendUsingAccount = acc;

            ((Outlook._AppointmentItem)oAppointment).Send();

            String conversationId = oAppointment.ConversationID;

            Console.WriteLine("ConversationId: " + conversationId);

            String guid = oAppointment.GlobalAppointmentID;

            Console.WriteLine("guid: " + guid);

            ((Outlook._AppointmentItem)oAppointment).Close(Outlook.OlInspectorClose.olSave);

            //Outlook.MailItem mailItem = oAppointment.ForwardAsVcal();
            //     mailItem.SendUsingAccount = GetAccountForEmailAddress(application, fromAddress);
            //// email address to send to
            //     mailItem.To = "*****@*****.**";
            //
            //((Outlook._MailItem)mailItem).Send();

            return(guid);
        }