我有一个小问题不知道要解决。我正在使用 C#、Visual Studio 2010 和我正在使用 Outlook 库的错误页面。在我的项目中,我添加了以下库:“Microsoft.Office.Interop.Outlook” 如果我使用 Visual Studio 提供的服务器运行网站,则该页面可以完美运行。如果我通过 IIS 运行该页面,日志显示我:“由于以下错误,无法检索具有 CLSID {0006F03A-0000-0000-C000-000000000046} 的组件的 COM 类工厂:80070005 访问被拒绝。(来自 HRESULT 的异常:0x80070005(E_ACCESSDENIED))。”
有谁知道这是为什么?我应该怎么做才能修复它?
我想使用 c# 创建一个 Outlook 约会,将此约会保存在我的一个服务器文件夹中,然后将其作为附件发送到电子邮件中,我该怎么做?
我的代码是这样的:
using Microsoft.Office.Interop;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Net.Mail;
Outlook.Application outlookApp = (Outlook.Application)new Outlook.Application();
Outlook.AppointmentItem appointment = (Outlook.AppointmentItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
appointment.Subject = subject;
appointment.Body = comments;
appointment.Location = location;
appointment.StartUTC = dateInit;
appointment.EndUTC = dateEnd;
appointment.ReminderSet = true;
appointment.ReminderMinutesBeforeStart = advideInMinutes;
appointment.BusyStatus = Microsoft.Office.Interop.Outlook.OlBusyStatus.olBusy;
string appointmentPath = "c:\\webroot\\appointment\\appointmentName.msg";
appointment.SaveAs(appointmentPath);
MailMessage mail = new MailMessage();
mail.To.Add(new System.Net.Mail.MailAddress("mail@domain.com"));
mail.From = new System.Net.Mail.MailAddress("mail@domain.com", "MyName", System.Text.Encoding.UTF8);
mail.SubjectEncoding = System.Text.Encoding.UTF8;
mail.BodyEncoding = System.Text.Encoding.UTF8;
mail.IsBodyHtml = true;
mail.Priority = MailPriority.Normal;
Attachment appointmentAttahment = new Attachment(appointmentPath);
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("authsmtp.mydomain.com");
smtp.Credentials = new System.Net.NetworkCredential(Settings.Items["mail@domain.com", "password");
smtp.EnableSsl = false;
smtp.Send(mail);
appointmentAttahment.Dispose();