I have a little problem that I don't know to solve. I'm working with C#, Visual Studio 2010 and the error page that I have I am using Outlook libraries. In my project I added the following library: "Microsoft.Office.Interop.Outlook" If I run the website using the server that Visual Studio gives me, the page works perfectly. If I run the page through IIS, logging says me: "Could not retrieve the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))."
Does anyone know why that is? What should I do to fix it?
I want to create an outlook appointment using c#, save this appointment in one of my server folders and then send it attached in an email, how can I do it?
My code is this:
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("[email protected]"));
mail.From = new System.Net.Mail.MailAddress("[email protected]", "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["[email protected]", "password");
smtp.EnableSsl = false;
smtp.Send(mail);
appointmentAttahment.Dispose();