We help IT Professionals succeed at work.

Creating Outlook Appointment from a .NET application

669 Views
Last Modified: 2013-11-25
I've read the thread on the following topic,
Creating Outlook Task from a .NET application in order to create an Outlook Appt for a .NET Web Application.  I've gotten it to work as a console application, but not a web application.   I'm currently stuck.
I've created an Outlook profile, called "ASPNET" to access my inbox. (I"m developing on my machine).  I have "ASPNET" set as the default profile for when Outlook opens up.  But, I must be missing something else.  I'm currently getting the following error, "The server is not available. Contact your administrator if this condition persists."   This is happening when trying to login to the namespace.  I have no idea what server the message is talking about.  Can anyone help?  I've played around and also received the "can't login to MAPI when another MAPI login is happening" (or something like that).  I just can't seem to get past this Namespace Logon statement.  Please help...

Here's my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        ' Create an Outlook application.
        Dim oApp As Outlook.Application = New Outlook.Application
       
        ' Get Mapi NameSpace and Logon.
        Dim oNS As Outlook.NameSpace = oApp.GetNamespace("MAPI")
        oNS.Logon("ASPNET", Missing.Value, False, True) ' TODO:

        ' Create an AppointmentItem.
        Dim oAppt As Outlook._AppointmentItem = oApp.CreateItem(Outlook.OlItemType.olAppointmentItem)
        'oAppt.Display(true)  'Modal      

        ' Change AppointmentItem to a Meeting.
        oAppt.MeetingStatus = Outlook.OlMeetingStatus.olMeeting

        ' Set some common properties.
        oAppt.Subject = "Created using OOM in VB.NET"
        oAppt.Body = "Hello World"
        oAppt.Location = "Samm E"

        oAppt.Start = Convert.ToDateTime("04/15/2004 9:00:00 AM")
        oAppt.End = Convert.ToDateTime("04/15/2004 1:00:00 PM")

        oAppt.ReminderSet = True
        oAppt.ReminderMinutesBeforeStart = 5
        oAppt.BusyStatus = Outlook.OlBusyStatus.olBusy  '  olBusy
        oAppt.IsOnlineMeeting = False
        oAppt.AllDayEvent = False

        ' Add attendees.
        Dim oRecipts As Outlook.Recipients = oAppt.Recipients

        ' Add required attendee.
        Dim oRecipt As Outlook.Recipient
        oRecipt = oRecipts.Add("DS Change Request Calendaar") ' TODO:
        oRecipt.Type = Outlook.OlMeetingRecipientType.olRequired

        '' Add optional attendee.
        'oRecipt = oRecipts.Add("UserTest2") ' TODO:
        'oRecipt.Type = Outlook.OlMeetingRecipientType.olOptional

        oRecipts.ResolveAll()

        'oAppt.Display(true)

        ' Send out request.
        oAppt.Send()

        ' Logoff.
        oNS.Logoff()

        ' Clean up.
        oApp = Nothing
        oNS = Nothing
        oAppt = Nothing
        oRecipts = Nothing
        oRecipt = Nothing
    End Sub
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
My suggestion would be to put this line in the web.config file:

<identity impersonate="true" />

Author

Commented:
I tried your suggestion, but it didn't work.
I have Outlook 2000 installed on my machine.  When I started the web application, Outlook was not running, however, I have the properties set to use the profile "ASPNET" as the default when Outlook opens.
I added the "Identity impersonate" line to the web.config file.
What happens is it seems to hangs on:

 Dim oApp As Outlook.Application = New Outlook.Application

After a few minutes, it comes back with a "Server execution failed" error.

I then tried it with Outlook open and running, again with "ASPNET" as the default profile.  Same thing happens.

I don't see any type of dialog box asking for information.  I thought there might be one that I can't see and the web page is hanging waiting for a user response.

Anyway, I then set the "Identity Impersonate" back to false and I'm back to where I started.  I had Outlook open when I run the application this time, and I get as far as the namespace logon and then receive the following error:

"Exception Details: System.Runtime.InteropServices.COMException: The server is not available. Contact your administrator if this condition persists."

I have no idea what server this error is talking about.

Any other ideas??

Author

Commented:
Correction to my last comment.  I'm running Outlook 2002 sp1, not Outlook 2000.
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
The ASP.NET security model is a very tricky beast!!!!!   Especially when dealing with COM objects.

PRB: "Access Denied" Error Message When You Call a Web Service While Anonymous Authentication Is Turned Off
http://support.microsoft.com/default.aspx?scid=kb;en-us;811318

PRB: "Access Denied" Error Message Occurs When You Impersonate an Account in ASP.NET and Then Call STA COM Components
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q325791

Bob

Author

Commented:
Thanks.  I'll take a look.  I'll be out for a long weekend, so will get back to you sometime next Tuesday on whether this helped or not.

Note,  I was wondering if my company's proxy server was causing the problem.  I do have my Internet Options/Connections/Lan Settings set to Bypass the proxy server for local connections, though.

Gail
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
Does Outlook connect through the proxy to get to server on the outside?  Or is it on the inside?

Bob

Author

Commented:
Hi,  I'm back from a long weekend.  In your question you ask "Does Outlook connect through the proxy to get to the server".  What server are you talking about?  The web server or the exchange server?  The web application will be inside our firewall, on our company's intranet.

Author

Commented:
According to one of our network people, "Outlook is a client that directly connects to our Exchange servers.  The Outlook client is unaware of a Proxy Server."  Does this help?  
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008

Commented:
The web server in this case is the client that connects to the Exchange server.  Is the web server on the inside with the Exchange server, or does it connect through the firewall to the outside.

Bob

Author

Commented:
Hi,
   Just wanted to let you know.  I was able to finally logon to the namespace.  My co-worker suggested the same thing you did, Bob, using <identity impersonate="true" /> , but with a username and password.  This did the trick.
   However, I"ve noticed that even though my code has the following lines in it:


 ' Logoff.
        oNS.Logoff()

        outlookApp.Quit()

        outlookApp = Nothing
        oNS = Nothing

The program leaves an instance of Outlook running after it's closed.
Any ideas?
CERTIFIED EXPERT
Most Valuable Expert 2012
Top Expert 2008
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.