tags:

views:

1043

answers:

4

I am trying to send an outlook appointment through code. My code is posted below. When I run it on the server with IIS 6 and an app pool under a domain account identity, it throws this error. I have tried changing various settings on the server and none worked. Outlook 2007 is installed. I have even made the domain account a local admin. Please help!

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Runtime.InteropServices.COMException: Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))

Line 201: objAppt.Send();

Code below:

Microsoft.Office.Interop.Outlook.Application objOL 
    = new Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.AppointmentItem objAppt 
    = (Microsoft.Office.Interop.Outlook.AppointmentItem)objOL
        .CreateItem
            (Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
objAppt.Start = startTime;//datetime
objAppt.End = endTime;//datetime
objAppt.Subject = subject;
objAppt.Body = body;
objAppt.Location = location;
objAppt.MeetingStatus 
    = Microsoft.Office.Interop.Outlook.OlMeetingStatus.olMeeting;
objAppt.RequiredAttendees = "[email protected]";
objAppt.Send();
objAppt = null;
objOL = null;
A: 

Quite simply, you shouldn't be doing this. It is not recommended that you run Office in a server environment because of the threading (and desktop session) requirements that Office has.

Are you trying to do this on an Exchange server? If so, then I would interact directly with the Exchange server (using WebDAV perhaps?).

If not connecting with Exchange, then take a look at the headers for an invitation to the event. The invitations should be nothing more than regular emails with custom header information.

casperOne
No, it is not an Exchange server. So it is not recommended to use the Office interop objects on the servers? But I just can't figure out how to make it work...
@tom: Well, this is only an email with some extra headers attached. Send one to yourself and take a look at the headers that are in the email, and then duplicate them appropriately.
casperOne
"Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment."http://support.microsoft.com/kb/257757
tomfanning
Thank you very much!
A: 

Yes as casperOne said I wouldn't use outlook on the server. I would use CDO or RDO(redemeption) for this. or even use vcal and send the vcal on a system.Net.Mail.

Update: Take a look at http://www.dimastr.com/redemption/rdo/RDOAppointmenItem.htm

Show you how to do excatly what you want to do using RDO. You can do the same with CDO as well. Check out CDOLive.com You will have to construct a teh login details as you are on a server that has no Outlook profile (thats if you remove the one that you allready have on there)

76mel
Great info. Thanks a lot!
A: 

I guess the reason you cannot use Outlook from an IIS application is because the current user the IIS app is running under does not have an Outlook profile associated.

Therefore you can instantiate Outlook objects and set their properties, until profile-specific functionality is required, such as the Send() command, which would store the outgoing mail in the user's/profile's (non-existing) pst file.

devio
I indeed created a profile for that user account, but...
A: 

Don't do this using Outlook automation.

Straight from the horse's mouth:

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

http://support.microsoft.com/kb/257757

Examine email headers sent by Outlook when it's doing this job to work out how this is done, and emulate it using the standard .NET SmtpClient stuff.

tomfanning