[英]Create Outlook appointment via C# .Net
我需要使用microsoft.office.interop.outlook
创建一个 Outlook 约会,但是虽然我可以让它在我自己的工作站上本地工作,并且如果我通过服务器的浏览器运行 Web 应用程序它也可以工作,它在我时不起作用从外部连接到服务器。
因此,我认为这可能是一个许可问题。
我将application pool identity
更改为“ LocalSystem
”,所以现在我没有收到拒绝访问错误。 不幸的是,它实际上不起作用。
该应用程序的行为就像约会已成功创建,但约会未出现在 Outlook 中。
这是我的 aspx.cs 页面顶部的包含文件
using Outlook = Microsoft.Office.Interop.Outlook;
这是我用来弹出约会的代码。
Outlook.Application apptApp = new Outlook.Application();
Outlook.AppointmentItem appt =
apptApp.CreateItem(Outlook.OlItemType.olAppointmentItem) as Outlook.AppointmentItem;
appt.Subject = txtFirstName.Text + " " + txtLastName.Text;
appt.Body = txtComment.Text;
appt.AllDayEvent = false;
appt.Start = DateTime.Parse(txtReminderDate.Text + " 8:00 AM");
appt.End = DateTime.Parse(txtReminderDate.Text + " 9:00 AM");
appt.Display(false);
正如我所说,如果我在服务器上使用localhost
,它可以工作,但是如果我尝试通过另一台机器从外部访问该应用程序,它什么也不做。
我确实在服务器上安装了Outlook 2003
以访问 interop.outlook 文件并添加了对microsoft.office.core
的引用。
任何帮助将不胜感激,谢谢!
在您的 web.config 文件中设置授权访问:
<system.web>
<authorization>
<deny users="?"/>
</authorization>
</system.web>
如果有帮助,我使用以下方法创建 Outlook 约会:
private void CreateOutlookGroupMeetingAppointment(List<string> emailRecipients, string meetingPlace, string shortDescription, string longDescription, DateTime start, DateTime finish)
{
try
{
Microsoft.Office.Interop.Outlook.Application ApplicationInstance = null;
Microsoft.Office.Interop.Outlook.AppointmentItem AppointmentInstance = null;
ApplicationInstance = new Microsoft.Office.Interop.Outlook.Application();
AppointmentInstance = (Microsoft.Office.Interop.Outlook.AppointmentItem) ApplicationInstance.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
foreach (string EmailRecipient in emailRecipients)
{
AppointmentInstance.Recipients.Add(EmailRecipient);
}
AppointmentInstance.Subject = shortDescription;
AppointmentInstance.Body = longDescription;
AppointmentInstance.Location = meetingPlace;
AppointmentInstance.Start = start;
AppointmentInstance.End = finish;
AppointmentInstance.ReminderSet = true;
AppointmentInstance.ReminderMinutesBeforeStart = 15;
AppointmentInstance.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh;
AppointmentInstance.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
AppointmentInstance.Save();
AppointmentInstance.Send();
}
catch //(Exception ex)
{
//ex.HandleException();
}
}
我使用 .Net 4.5,并引用名为“Microsoft.Office.Interop.Outlook”(版本 15.0.0.0,文件版本 15.0.4420.1017)的扩展(项目 => 添加引用)
您应该尝试使用 EWS(交换 Web 服务),而不是使用 Outlook 互操作。 至于您当前的问题,当您将其部署到外部机器时,您的服务在什么凭据下运行? 我们遇到了您/您的机器可以访问 Outlook 服务器的问题,因此当您在本地运行它时,一切正常。 但是,当您将其部署到计算机时,它会在没有适当权限的不同凭据下运行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.