Trying to read outlook email without having outlook runningprogrammatically

  • Thread starter Thread starter daniel.p.nguyen
  • Start date Start date
D

daniel.p.nguyen

Hi,

I was hoping someone could give me a hand.

I wrote a program to automatically read email from outlook. The
application successfully read email from outlook when outlook is
opened. But when I shut down outlook, the program can no longer read
email. Or it other words it doesn't have access to exchange server.

Other notes, I have cached mode turn off for this specific email
account because I always want to be able to read the latest email.
Cache mode does not reliably guaranteed that I will get the latest
mail when trying to retrieve mail programmatically.

So this is the error which comes back when I try to access email when
Outlook is not running.

Does any one know if it is even possible to read email when an
instance of outlook is not running (the email account having cache
mode turn off)? If it is possible, do you know how to go about it?

Here is the code which I use to retrieve email from outlook. It's in
C# but i'm sure it's very similar in VB.

// #################################################
using Microsoft.Office.Interop.Outlook;
..
..
..
Application myOutLook = new Application();
myOutlook.Session.Logon(userName, password, false, false);
// #################################################

this code works perfectly fine when I have outlook open. But when I
shut down outlook, this is the error which I receive.

"The server is not available. Contact your administrator if the
condition persists."

And if you are thinking that exchange might be down, then nope.
Exchange is available.

So if any one can lend a hand, I would greatly appreciate it. Thanks
in advance.
 
As far as I know you have to Outlook running to access folders, etc.

This code will check for an existing instance of Outlook, and if it
isn't open, it starts one. GetObject will return the running instance,
otherwise CreateObject will create it. The code will exit if neither
is possible.

Dim olApp As Object ' Dim olApp As Outlook.Application if you set a
reference to Outlook object library
Application.StatusBar = "Checking For Existing Copy of Outlook..."
' test for instance of Outlook, exit if not able to start one
On Error Resume Next
Set olApp = GetObject(, "Outlook.Application")
If Err.Number <> 0 Then
Set olApp = CreateObject("Outlook.Application")
End If
On Error GoTo 0

If olApp Is Nothing Then
Application.StatusBar = False
MsgBox "Cannot start Outlook. Please open Outlook and try again.",
_
vbInformation
Exit Sub
End If


HTH,
JP
 
Back
Top