Eliseo
Eliseo

Reputation: 416

Create Outlook appointment via C# .Net

I need to create an Outlook appointment using microsoft.office.interop.outlook, however while I can get it to work locally on my own workstation and it also works if I run the web application via the server's browser, it does not work when I connect to the server externally.

Hence, I think it might be a permission issue.

I changed the application pool identity to "LocalSystem" So now I don't get an access denied error. Unfortunately, it doesn't actually work.

The app behaves as if the appointment was successfully created, but the appointment doesn't appear in Outlook.

Here is my include file on top of my aspx.cs page

using Outlook = Microsoft.Office.Interop.Outlook;

Here is the code I am using to pop up the appointment.

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);

As I said it works if I use localhost on the server, but if I try to access the app externally via another machine it does nothing.

I did install Outlook 2003 on the server to get access to the interop.outlook file and added a reference to microsoft.office.core.

Any help would be greatly appreciated, thanks!

Upvotes: 3

Views: 8797

Answers (3)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66215

No Office app (Outlook included) can be used in a service (including IIS).

Your options are

  1. In case of an Exchange Server, use EWS to access the mailbox.

  2. Extended MAPI (C++ or Delphi only)

  3. Redemption (I am its author, any language) - it wraps Extended MAPI and its RDO family of objects can be used from a service.

Upvotes: 0

WonderWorker
WonderWorker

Reputation: 9062

Set up the authorization access in your web.config file:

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

In case it helps, I use the following method to create Outlook appointments:

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();

    }

}

I use .Net 4.5, and reference the extension (Project => Add reference) called, 'Microsoft.Office.Interop.Outlook' (Version 15.0.0.0, File version 15.0.4420.1017)

Upvotes: 5

KnightFox
KnightFox

Reputation: 3252

Rather than using outlook interop, you should try using EWS (exchange web services). As for your current problem, what credentials is your service running under when you deploy it to the external machine ? We have run into issues where you/your machine has access to the outlook server hence when you run it locally, everything works. However, when you deploy it to a machine, it runs under different credentials that do not have the appropriate permissions.

Upvotes: 0

Related Questions