limited outlook 2003 mapi connections?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a VB Script which will use default profile to search user mailbox. It
works fine but stopped after accessing 70 mailboxes. Then it pops up a
screen like the first time you launch Outlook without any profile, asking for
Exchange server and mailbox name, etc. But if you type in a correct
servername and mailbox name then you will get "outlook can not connect to
Exchange server...". I guess there is a restriction in Outlook 2003 that how
many connections it can generate. Is that right? and any workaround such as
a command to ternimate outook connection? or increase the limit or get rid
of the limit completely?

Thanks.
 
Probably the 255 RPC channel limit on online connections to the Exchange
server. That's set in a registry setting on the server.

Release all your objects explicitly on each pass through your loop so the
channels are closed. Make sure to reduce the number of dot operators because
Outlook creates internal objects for each dot operator and doesn't release
them until the procedure ends. If you explicitly instantiate each object you
can control releasing it. Instead of Application.Session.GetItemFromID(sID,
sStore) do this:

Set ns = Application.GetNameSpace("MAPI")
Set oMail = ns.GetItemFromID(sID, sStore)

and so on.

If necessary process fewer items per call to the procedure and call the loop
procedure multiple times.
 
Are you using GetSharedFolder for that?
Do you reset all unused variables to Nothing immediately after you are done
with them?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
be honest with you, I have no idea of Outlook programming. I got it from
other. I think it's really a ADO stuff. Could you take a look for me?
 
I have no idea of Outlook programming. I got the script from other people. I
think it's ADO stuff. Could you take a look for me? I can post or send you
a copy.
 
here is the script if anyone can help me. Basically, it's checking if any
forarding rules have been set in each mailbox. Our users use Delegation a
lot. But when people left they don't get removed from Delegation list and
others wil get NDR. The script is very helpful. The only problem with me is
that once accessing about 70 mailboxes it issues "open mailbox error" till
the end.

servername = wscript.arguments(0)
PR_HAS_RULES = &H663A000B
PR_URL_NAME = &H6707001E
PR_CREATOR = &H3FF8001E
Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\MeetingDelgatesForwards.csv",2,true)
wfile.writeline("Mailbox,ForwadingAddress,Status")
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("configurationNamingContext")
strDefaultNamingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
svcQuery = "<LDAP://" & strNameingContext &
">;(&(objectCategory=msExchExchangeServer)(cn=" & Servername &
"));cn,name,legacyExchangeDN;subtree"
Com.ActiveConnection = Conn
Com.CommandText = svcQuery
Set Rs = Com.Execute
while not rs.eof
GALQueryFilter = "(&(&(&(&
(mailnickname=*)(!msExchHideFromAddressLists=TRUE)(|
(&(objectCategory=person)(objectClass=user)(msExchHomeServerName=" &
rs.fields("legacyExchangeDN") & ")) )))))"
strQuery = "<LDAP://" & strDefaultNamingContext & ">;" & GALQueryFilter &
";distinguishedName,mailnickname,mail;subtree"
com.Properties("Page Size") = 100
Com.CommandText = strQuery
Set Rs1 = Com.Execute
while not Rs1.eof
call procmailboxes(servername,rs1.fields("mail"))
wscript.echo rs1.fields("mail")
rs1.movenext
wend
rs.movenext
wend
rs.close
wfile.close
set fso = nothing
set conn = nothing
set com = nothing
wscript.echo "Done"




sub procmailboxes(servername,MailboxAlias)

Set msMapiSession = CreateObject("MAPI.Session")
on error Resume next
msMapiSession.Logon "","",False,True,True,True,Servername & vbLF &
MailboxAlias
if err.number = 0 then
on error goto 0
Set mrMailboxRules = CreateObject("MSExchange.Rules")
mrMailboxRules.Folder = msMapiSession.Inbox
Wscript.echo "Checking For any Delegate forwarding Rules"
nfNonefound = 0
for Each roRule in mrMailboxRules
for each aoAction in roRule.actions
if aoAction.ActionType = 7 then
nfNonefound = 1
Wscript.echo "Delegate Rule found Forwards to"
for each aoAdressObject in aoAction.arg
Set objAddrEntry = msMapiSession.GetAddressEntry(aoAdressobject)
wscript.echo "Address = " & objAddrEntry.Address
if verifyaddress(objAddrEntry.Address) = 1 then
wfile.writeline(mailboxAlias & "," & objAddrEntry.Address & ",Account
Valid")
wscript.echo "Account okay"
else
wscript.echo "Account not valid"
wfile.writeline(mailboxAlias & "," & objAddrEntry.Address & ",Account
Invalid")
end if
next
end if
next
next
if nfNonefound = 0 then
wscript.echo "No Delegate forwarding rules found"
wfile.writeline(mailboxAlias & "," & "No Delegate forwarding rules found")
end if
else
Wscript.echo "Error Opening Mailbox"
wfile.writeline(mailboxAlias & "," & "Error Opening Mailbox")
end if
Set msMapiSession = Nothing
Set mrMailboxRules = Nothing

End Sub

function verifyaddress(exlegancydn)

vfQuery = "<LDAP://" & strDefaultNamingContext & ">;(legacyExchangeDN=" &
exlegancydn & ");name,distinguishedName;subtree"
Com.CommandText = vfQuery
Set Rschk = Com.Execute
aoAccountokay = 0
While Not Rschk.EOF
set objUser = getobject("LDAP://" &
replace(rschk.fields("distinguishedName"),"/","\/"))
if objUser.AccountDisabled then
aoAccountokay = 0
else
aoAccountokay = 1
end if
rschk.movenext
wend
rschk.close
set rschk = nothing
set connchk = nothing
set comchk = nothing
verifyaddress = aoAccountokay

end function
 
Your code is a mixture of CDO 1.21 and LDAP code. I wouldn't even begin to
start analyzing it.

This is an Exchange programming problem, it really should be posted to an
Exchange programming group.
 
Firstly, your code never calls msMapiSession.Logoff.
Secondly, creating new sessions for each user is not the best way to open
multiple mailboxes, but unfortunately that is the best you can do with CDO
1.21.
On the Extended MAPI level (Outlook does that as well), you'd need to log to
the mailbox of the current user, then open other mailboxes in the same
session using IExchangeManageStore. Outlook uses it when you call
Namespace.GetSharedDefaultFolder. <plug> Redemption (url below) allows to
open other users' mailboxes using RDOSession.Stores.GetSharedMailbox </plug>

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Dmitry,
Thanks for your reply. Another question. Do you know if Exchage 2003
allow you to open mapi connections to each mailbox? It seems to me that it's
a security issue MS might block it. When I ran the script it can access
about 70 mailboxes, then got "error open mailbox". I guess it's not a
permission issue otherwise I won't be able to access at all. I think that
there maybe be a built-in security in Exchange which stopped it because it
thinks it's more like a virus or hacking activity. But I can't find anything
on MS support site. Are you aware such function in Exchange 2003? I'm
running sp2

Thanks.
 
Back
Top