Solved

Creating Outlook Appointment from a .NET application

Posted on 2004-04-07
13
593 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
0
Comment
Question by:lbrties
  • 6
  • 5
13 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10777559
My suggestion would be to put this line in the web.config file:

<identity impersonate="true" />
0
 

Author Comment

by:lbrties
ID: 10784958
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
 

Author Comment

by:lbrties
ID: 10785224
Correction to my last comment.  I'm running Outlook 2002 sp1, not Outlook 2000.
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10785962
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
 

Author Comment

by:lbrties
ID: 10786488
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 10786608
Does Outlook connect through the proxy to get to server on the outside?  Or is it on the inside?

Bob
0
 

Author Comment

by:lbrties
ID: 10812883
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
 

Author Comment

by:lbrties
ID: 10813027
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 10822717
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
 

Author Comment

by:lbrties
ID: 10918585
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 250 total points
ID: 10918677
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now