Outlook集成 - 约会发送事件

时间:2016-12-13 14:56:40

标签: c# events outlook outlook-addin

我遇到了问题"发送" Outlook库的AppointmentItem事件。

每当我试图将一些方法或行动分配给"发送"事件,抛出以下错误。有人可以向我解释或帮助我吗?

我知道有发送活动:here

https://msdn.microsoft.com/en-us/library/office/ff865990.aspx

这是我的代码:

 private void btnOutlookCalendar_Click(object sender, RoutedEventArgs e)
    {
        System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");
        Outlook.Application outlookApp;
        int collCount = processes.Length;

        if (collCount != 0)

        {

            // Outlook already running, hook into the Outlook instance
            outlookApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;

        }
        else
        {
            outlookApp = new Microsoft.Office.Interop.Outlook.Application(); //neues Outlook Objekt erzeugen
        }

        Outlook.AppointmentItem oAppointment;

        oAppointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Outlook.OlItemType.olAppointmentItem); // neuen Kalendereintrag erstellen

        oAppointment.Subject = this.dtoEvent.Bezeichnung; // set the subject
        oAppointment.Body = "Automatisch durch das X erstelltes Event\n\n"
            + this.dtoEvent.Beschreibung + "\nWeitere Informationen:\n"
            + "X" + this.dtoEvent.ID;
        oAppointment.Location = this.dtoEvent.Ort + ", " + this.dtoEvent.Strasse; // set the location

        oAppointment.Start = Convert.ToDateTime(this.dtoEvent.Datum_Von + " " + this.dtoEvent.Uhrzeit_Von); // Set the start date 
        oAppointment.End = Convert.ToDateTime(this.dtoEvent.Datum_Bis + " " + this.dtoEvent.Uhrzeit_Bis); // End date             

        oAppointment.ReminderSet = true; // Set the reminder
        oAppointment.ReminderMinutesBeforeStart = 15; // reminder time
        oAppointment.Importance = Outlook.OlImportance.olImportanceHigh; // appointment importance
        oAppointment.BusyStatus = Outlook.OlBusyStatus.olBusy;

        this.oAppointment = oAppointment; 

        oAppointment.Display(true);

        oAppointment.Send += _appointment_Send;

    }



    private void _appointment_Send(ref bool Cancel)
    {
        if (MessageBox.Show("Wollen Sie die Veranstaltung per E-Mail verschicken?", "Frage", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
        {
            Outlook.MailItem mailItem = ((Outlook.AppointmentItem)oAppointment).ForwardAsVcal();

            mailItem.Body = "X";

            mailItem.Display();


        }
    }

1 个答案:

答案 0 :(得分:1)

如果您查看警告消息,可以看到以下内容:

  

警告1方法'Microsoft.Office.Interop.Outlook._MailItem.Send()'与非方法'Microsoft.Office.Interop.Outlook.ItemEvents_10_Event.Send'之间存在歧义。使用方法组。

因此,为了避免此类错误或警告,您可以将邮件项目对象强制转换为Microsoft.Office.Interop.Outlook.ItemEvents_10_Event界面:

 (mail as Microsoft.Office.Interop.Outlook.ItemEvents_10_Event).Send += AddinModule_Send;

如果您想使用Send方法,则需要将项目对象转换为_MailItem类。