• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

Creating Outlook Appointment from a .NET application

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
0
lbrties
Asked:
lbrties
  • 6
  • 5
1 Solution
 
Bob LearnedCommented:
My suggestion would be to put this line in the web.config file:

<identity impersonate="true" />
0
 
lbrtiesAuthor 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??
0
 
lbrtiesAuthor Commented:
Correction to my last comment.  I'm running Outlook 2002 sp1, not Outlook 2000.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Bob LearnedCommented:
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
0
 
lbrtiesAuthor 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
0
 
Bob LearnedCommented:
Does Outlook connect through the proxy to get to server on the outside?  Or is it on the inside?

Bob
0
 
lbrtiesAuthor 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.
0
 
lbrtiesAuthor 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?  
0
 
Bob LearnedCommented:
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
0
 
lbrtiesAuthor 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?
0
 
Bob LearnedCommented:
COM:  Release Objects:

' Release the object through the COM interoperability.
System.Runtime.InteropServices.Marshal.ReleaseComObject(object)

' Force garbage collection.
GC.Collect

Remember to release all COM objects:  Application, worksheet, document, etc.

Bob
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now