2009-12-23 70 views
5

我想使用下面的代码在另一个人的Microsoft Outlook(2003)日历中创建约会。在运行此程序时,约会被保存在我的日历中,但未被发送给收件人。如何创建并向Microsoft Outlook日历发送约会?

try 
{ 
    Microsoft.Office.Interop.Outlook.Application app = null; 
    Microsoft.Office.Interop.Outlook.AppointmentItem appt = null; 

    app = new Microsoft.Office.Interop.Outlook.Application(); 

    appt = (Microsoft.Office.Interop.Outlook.AppointmentItem)app 
     .CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem); 
    appt.Subject = "Meeting "; 
    appt.Body = "Test Appointment body"; 
    appt.Location = "TBD"; 
    appt.Start = Convert.ToDateTime("12/23/2009 05:00:00 PM"); 
    appt.Recipients.Add("[email protected]"); 
    appt.End = Convert.ToDateTime("12/23/2009 6:00:00 PM"); 
    appt.ReminderSet = true; 
    appt.ReminderMinutesBeforeStart = 15; 
    appt.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; 
    appt.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy; 
    appt.Save(); 
    appt.Send(); 
} 
catch (COMException ex) 
{ 
    Response.Write(ex.ToString()); 
} 

我是否缺少任何东西?任何人都可以帮我解决这个问题吗?

回答

3

尝试增加:

appt.MeetingStatus = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting; 

默认状态是预约这我不知道被发送。

5

之后,你有约会:

Outlook.MailItem mailItem = appt.ForwardAsVcal(); 
mailItem.To = "recipient's email address"; 
mailItem.Send(); 
1

这是我如何解决了这个问题:

我把(如桑尼男孩的帖子):

但我也不得不创建一个web.config文件,并设置授权访问以避免任何COMException:

<system.web> 
    <authorization> 
    <deny users="?"/> 
    </authorization> 
</system.web>