Read Emails on Exchange server without OL client

  • Thread starter Thread starter Bryan Dickerson
  • Start date Start date
No you won't see MicrosoftExchangeV2 there.

You are connecting remotely to the exchange server I take it? There is no
such animal on Windows XP.

I will need to modify my code sample. I was under the impression you were
running this local to the server.

I will need to connect you remotely to the given server. However, your WMI
issue will still need to be resolved.

I strongly suggest while I am working on this issue of you connecting to teh
exchange server remotely that you contact your admin or boss and obtain
permission for me to come in and set up your WMI properly. I can't guess
anymore what you are seeing and what your issues are.

Regardless, I hope to have a remote example for you shortly.
 
Is there no documentation or instructions anywhere on how WMI needs to be
setup like you would do? Can you reply with those setup instructions? I'll
be honest: I am more than thankful of the help that you have been so far,
but I'm a bit put-off by your insistence at a remote session on my box. I
can follow instructions fairly well, if you can either write them down or
tell me where to look for them.
 
Assuming you are doing this on an internal network and not from outside. Pay
attention to "ENTERDOMAIN", "enterpassword", "SERVERNAME", "YOUR NAME". Make
sure WMI has remote permissions enabled on the server. If you don't know how
to do this or sys admin does not know how, email me off list to arrange a
remote desktop session with me.

Private Sub SimpleStuff()
Try
Dim connection As New Management.ConnectionOptions
connection.Username = "Administrator"
connection.Password = "enterpassword"
connection.Authority = "ntlmdomain:ENTERDOMAIN"

Dim scope As New Management.ManagementScope( _
"\\SERVERNAME\root\MicrosoftExchangeV2", connection)
scope.Connect()

Dim query As New Management.ObjectQuery( _
"SELECT * FROM Exchange_Mailbox WHERE MailboxDisplayName
= 'YOUR NAME'")

Dim searcher As New Management.ManagementObjectSearcher(scope,
query)

For Each queryObj As Management.ManagementObject In
searcher.Get()
Debug.WriteLine(queryObj("Size") & vbTab &
queryObj("TotalItems"))
'If these items are greater than 0 then exit For and do something with it,
send an email or something
Next

Catch err As Management.ManagementException
MessageBox.Show("An error occurred while querying for WMI data:
" & err.Message)
Catch unauthorizedErr As System.UnauthorizedAccessException

MessageBox.Show("Connection error (user name or password might
be incorrect): " & unauthorizedErr.Message)
End Try
End Sub
 
If there were one size fits all set of instructions existed, guys in IT
would not be employed. There are many things that can impact the ability to
communicate with a server to do what we are doing. Firewalls, routers, WMI
permissions, Exchange communication protocols (plain text or Windows
authentication), and the list goes on. I can't just throw things out there,
have ESP so to say and know what the answer is on issues I can't see or be
able to tell what your configuration is. I don't have anything nice to say
to your remark about being put off so I am going to leave it alone. I don't
think you would have found anyone else that would have stuck with you this
long.
 
I get this error:

'readExchange1.exe': Loaded
'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll',
No symbols loaded.
System.Runtime.InteropServices.COMException (0x80040154): Class not
registered
at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at readExchange1.Class1.Main(String[] args) in c:\documents and
settings\jbailo\my documents\visual studio
projects\readexchange1\class1.cs:line 30
The program '[1468] readExchange1.exe' has exited with code 0 (0x0).


For the line:

System.Management.ManagementObjectSearcher objsearch = new
System.Management.ManagementObjectSearcher(exmangescope,objquery);
 
What is your platform?

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com



John A. Bailo said:
I get this error:

'readExchange1.exe': Loaded
'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll',
No symbols loaded.
System.Runtime.InteropServices.COMException (0x80040154): Class not
registered
at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at readExchange1.Class1.Main(String[] args) in c:\documents and
settings\jbailo\my documents\visual studio
projects\readexchange1\class1.cs:line 30
The program '[1468] readExchange1.exe' has exited with code 0 (0x0).


For the line:

System.Management.ManagementObjectSearcher objsearch = new
System.Management.ManagementObjectSearcher(exmangescope,objquery);


Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace VIKINGSSUCK

Public Class THEPACKERSROCK

Function HELPMENOW()

Dim searcher As New ManagementObjectSearcher( _
"root\MicrosoftExchangeV2", _
"SELECT * FROM Exchange_Mailbox WHERE
MailboxDisplayName = 'Joe Schmo'")

For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("MailboxDisplayName: {0}",
queryObj("MailboxDisplayName"))
Console.WriteLine("Size: {0}", queryObj("Size"))
Console.WriteLine("TotalItems: {0}",
queryObj("TotalItems"))
Next
'if size or totalitems > 0 Then send an email to somebody here.

End Function
End Class
End Namespace
 
Are you connecting to an Exchange server on your local machine or another
server on your network? If so use this code:

Assuming you are doing this on an internal network and not from outside. Pay
attention to "ENTERDOMAIN", "enterpassword", "SERVERNAME", "YOUR NAME". Make
sure WMI has remote permissions enabled on the server. If you don't know how
to do this or sys admin does not know how, email me off list to arrange a
remote desktop session with me.

Private Sub SimpleStuff()
Try
Dim connection As New Management.ConnectionOptions
connection.Username = "Administrator"
connection.Password = "enterpassword"
connection.Authority = "ntlmdomain:ENTERDOMAIN"

Dim scope As New Management.ManagementScope( _
"\\SERVERNAME\root\MicrosoftExchangeV2", connection)
scope.Connect()

Dim query As New Management.ObjectQuery( _
"SELECT * FROM Exchange_Mailbox WHERE MailboxDisplayName
= 'YOUR NAME'")

Dim searcher As New Management.ManagementObjectSearcher(scope,
query)

For Each queryObj As Management.ManagementObject In
searcher.Get()
Debug.WriteLine(queryObj("Size") & vbTab &
queryObj("TotalItems"))
'If these items are greater than 0 then exit For and do something with it,
send an email or something
Next

Catch err As Management.ManagementException
MessageBox.Show("An error occurred while querying for WMI data:
" & err.Message)
Catch unauthorizedErr As System.UnauthorizedAccessException

MessageBox.Show("Connection error (user name or password might
be incorrect): " & unauthorizedErr.Message)
End Try
End Sub


--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com



John A. Bailo said:
I get this error:

'readExchange1.exe': Loaded
'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll',
No symbols loaded.
System.Runtime.InteropServices.COMException (0x80040154): Class not
registered
at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at readExchange1.Class1.Main(String[] args) in c:\documents and
settings\jbailo\my documents\visual studio
projects\readexchange1\class1.cs:line 30
The program '[1468] readExchange1.exe' has exited with code 0 (0x0).


For the line:

System.Management.ManagementObjectSearcher objsearch = new
System.Management.ManagementObjectSearcher(exmangescope,objquery);


Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace VIKINGSSUCK

Public Class THEPACKERSROCK

Function HELPMENOW()

Dim searcher As New ManagementObjectSearcher( _
"root\MicrosoftExchangeV2", _
"SELECT * FROM Exchange_Mailbox WHERE
MailboxDisplayName = 'Joe Schmo'")

For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("MailboxDisplayName: {0}",
queryObj("MailboxDisplayName"))
Console.WriteLine("Size: {0}", queryObj("Size"))
Console.WriteLine("TotalItems: {0}",
queryObj("TotalItems"))
Next
'if size or totalitems > 0 Then send an email to somebody here.

End Function
End Class
End Namespace
 
Ignore the remote desktop request that was from another user I had tried to
help. I suspect you wont need it.

--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com



John A. Bailo said:
I get this error:

'readExchange1.exe': Loaded
'c:\winnt\assembly\gac\system.xml\1.0.5000.0__b77a5c561934e089\system.xml.dll',
No symbols loaded.
System.Runtime.InteropServices.COMException (0x80040154): Class not
registered
at System.Management.ThreadDispatch.Start()
at System.Management.ManagementScope.Initialize()
at System.Management.ManagementObjectSearcher.Initialize()
at System.Management.ManagementObjectSearcher.Get()
at readExchange1.Class1.Main(String[] args) in c:\documents and
settings\jbailo\my documents\visual studio
projects\readexchange1\class1.cs:line 30
The program '[1468] readExchange1.exe' has exited with code 0 (0x0).


For the line:

System.Management.ManagementObjectSearcher objsearch = new
System.Management.ManagementObjectSearcher(exmangescope,objquery);


Imports System
Imports System.Management
Imports System.Windows.Forms

Namespace VIKINGSSUCK

Public Class THEPACKERSROCK

Function HELPMENOW()

Dim searcher As New ManagementObjectSearcher( _
"root\MicrosoftExchangeV2", _
"SELECT * FROM Exchange_Mailbox WHERE
MailboxDisplayName = 'Joe Schmo'")

For Each queryObj As ManagementObject in searcher.Get()
Console.WriteLine("MailboxDisplayName: {0}",
queryObj("MailboxDisplayName"))
Console.WriteLine("Size: {0}", queryObj("Size"))
Console.WriteLine("TotalItems: {0}",
queryObj("TotalItems"))
Next
'if size or totalitems > 0 Then send an email to somebody here.

End Function
End Class
End Namespace
 
This example takes me a little further, but is throwing an exception on
the searcher.Get() in the foreach loop:

An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
system.management.dll

Additional information: Class not registered



I recoded this in c#, here it is:


using System;
using System.Diagnostics;
using System.Management;


namespace readExchange1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
System.Management.ConnectionOptions connection = new
System.Management.ConnectionOptions();

connection.Impersonation = System.Management.ImpersonationLevel.Impersonate;

connection.EnablePrivileges = true;

string cServername = "MAILXXXX";
connection.Username = "jbailo";
connection.Password = "xxxxxxxx";
connection.Authority = "ntlmdomain:XXXXX";

try
{
System.Management.ManagementScope exmangescope
= new System.Management.ManagementScope(@"\\" + cServername +
@"\root\MicrosoftExchangeV2",connection);

System.Management.ObjectQuery objquery = new
System.Management.ObjectQuery("SELECT * FROM Exchange_Mailbox WHERE
MailBoxDisplayName='jbailo'");
System.Management.ManagementObjectSearcher objsearch = new
System.Management.ManagementObjectSearcher(exmangescope,objquery);
//System.Management.ManagementObjectCollection
//queryCollection1 = objsearch.Get();

string strDisplay=string.empty;

foreach( System.Management.ManagementObject instmailbox
in objsearch.Get() ) {
strDisplay = instmailbox["MailboxDisplayName"].ToString() + " " +
instmailbox["size"].ToString();
System.Console.WriteLine(strDisplay);
}
} catch(System.Management.ManagementException me) {
Debug.WriteLine(me.ToString());}
catch(System.UnauthorizedAccessException uae){
Debug.WriteLine(uae.ToString());
}}}}
 
http://groups.google.com/group/micr...40c6c8f4e11/484c2354cbfed848#484c2354cbfed848
--
Get a powerful web, database, application, and email hosting with KJM
Solutions
http://www.kjmsolutions.com



John A. Bailo said:
This example takes me a little further, but is throwing an exception on
the searcher.Get() in the foreach loop:

An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in
system.management.dll

Additional information: Class not registered



I recoded this in c#, here it is:


using System;
using System.Diagnostics;
using System.Management;


namespace readExchange1
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class Class1
{
static void Main(string[] args)
{
System.Management.ConnectionOptions connection = new
System.Management.ConnectionOptions();

connection.Impersonation =
System.Management.ImpersonationLevel.Impersonate;

connection.EnablePrivileges = true;

string cServername = "MAILXXXX";
connection.Username = "jbailo";
connection.Password = "xxxxxxxx";
connection.Authority = "ntlmdomain:XXXXX";

try
{
System.Management.ManagementScope exmangescope
= new System.Management.ManagementScope(@"\\" + cServername +
@"\root\MicrosoftExchangeV2",connection);

System.Management.ObjectQuery objquery = new
System.Management.ObjectQuery("SELECT * FROM Exchange_Mailbox WHERE
MailBoxDisplayName='jbailo'");
System.Management.ManagementObjectSearcher objsearch = new
System.Management.ManagementObjectSearcher(exmangescope,objquery);
//System.Management.ManagementObjectCollection
//queryCollection1 = objsearch.Get();

string strDisplay=string.empty;

foreach( System.Management.ManagementObject instmailbox
in objsearch.Get() ) {
strDisplay = instmailbox["MailboxDisplayName"].ToString() + " " +
instmailbox["size"].ToString();
System.Console.WriteLine(strDisplay);
}
} catch(System.Management.ManagementException me) {
Debug.WriteLine(me.ToString());}
catch(System.UnauthorizedAccessException uae){
Debug.WriteLine(uae.ToString());
}}}}





Are you connecting to an Exchange server on your local machine or another
server on your network? If so use this code:

Assuming you are doing this on an internal network and not from outside.
Pay
attention to "ENTERDOMAIN", "enterpassword", "SERVERNAME", "YOUR NAME".
Make
sure WMI has remote permissions enabled on the server. If you don't know
how
to do this or sys admin does not know how, email me off list to arrange a
remote desktop session with me.

Private Sub SimpleStuff()
Try
Dim connection As New Management.ConnectionOptions
connection.Username = "Administrator"
connection.Password = "enterpassword"
connection.Authority = "ntlmdomain:ENTERDOMAIN"

Dim scope As New Management.ManagementScope( _
"\\SERVERNAME\root\MicrosoftExchangeV2", connection)
scope.Connect()

Dim query As New Management.ObjectQuery( _
"SELECT * FROM Exchange_Mailbox WHERE
MailboxDisplayName
= 'YOUR NAME'")

Dim searcher As New
Management.ManagementObjectSearcher(scope,
query)

For Each queryObj As Management.ManagementObject In
searcher.Get()
Debug.WriteLine(queryObj("Size") & vbTab &
queryObj("TotalItems"))
'If these items are greater than 0 then exit For and do something with
it,
send an email or something
Next

Catch err As Management.ManagementException
MessageBox.Show("An error occurred while querying for WMI
data:
" & err.Message)
Catch unauthorizedErr As System.UnauthorizedAccessException

MessageBox.Show("Connection error (user name or password
might
be incorrect): " & unauthorizedErr.Message)
End Try
End Sub
 
Yes, I read that post yesterday and I went to the MS site to get the WMI
redistributable, however, I am running XP and that download is for:

System Requirements

* Supported Operating Systems: Windows 2000

I tried installing it and it would not install on XP.
 
Hi John,

Okay first after the scope.connect place this

MsgBox(scope.IsConnected.ToString)

and tell me its answer.

Also, make sure the display name for this exchange account is correct.

Add under the scope, query statement you currently have:

Dim searcher As New Management.ManagementObjectSearcher(scope, query)

If searcher.Get.Count = 0 Then
MsgBox("THERE WERE NONE")
Exit Sub
End If
if the count = 0 their is soemthing wrong with your display name or it does
not exist.

Kelly
 
So, I should run this install on that server? It's a w2k so it should
install.

BTW -- I tried connecting to another mail server which I think is
running w2003. There was no COM error, but it threw an authentication
error. (I locked myself out of my NT domain account by running it
actually!).

Anyway, I'm going to keep testing on the w2k server since its "safer".
 
Well, it looks like it's not letting me connect:


System.Management.ManagementScope exmangescope

= new System.Management.ManagementScope(@"\\" + cServername +
@"\root\MicrosoftExchangeV2",connection);

Debug.WriteLine("Connected? " + exmangescope.IsConnected.ToString());

Results in:

Connected? False
 
Can you tell me what the authentication error was? (text of error). Testing
on a production server is never advisable obviously.
 
OK now we are getting somewhere.

Run your install on 2000. Verify in component services under COM that remote
activiation and launch are allowed.
 
by the way you did run the

scope.connect statement prior to teh debug.writeline command right?
 
Back
Top