Using VB to Create E-mails

M

McKilty

Here's a strange problem that recently popped up. I have a program
that creates an e-mail in Office 2003 via Outlook Redemption. This
program has worked for months, but suddenly it stopped working.

The applicable code is:

Dim olOutlook As Outlook.Application
Dim nsNameSpace As Outlook.NameSpace
Dim oSession As MAPI.Session
Dim mFolder
Dim itmEmails As Items
Dim iCount, iEmail, iLate, iSub As Double
Dim oItem
Dim sEntry, sStore, sSQLText, sBCC, sCC, s1Day, s2Day, sGT2Day, sBody
As String
Dim oMessage As MAPI.Message
Dim NewMail
Dim SafeMail

Set olOutlook = New Outlook.Application
Set nsNameSpace = olOutlook.GetNamespace("MAPI")
Set oSession = CreateObject("MAPI.Session")

oSession.Logon "DS", , False, False

Set mFolder = nsNameSpace.Folders("Mailbox - Daily
Summary").Folders("DailySummaries")
Set itmEmails = mFolder.Items
Set itmEmails = itmEmails.Restrict("[ReceivedTime] < '" & Format(gDate
& " 11:59 PM", "MM/dd/yy hh:mm AMPM") & "'")

iCount = itmEmails.Count

For iEmail = 1 To iCount
Set oItem = itmEmails.Item(iCount - iEmail + 1)
sEntry = oItem.EntryID
sStore = oItem.Parent.StoreID

Set oMessage = oSession.GetMessage(sEntry, sStore)

Set NewMail = itmEmails.Item(iCount - iEmail + 1)
Set SafeMail = New Redemption.SafeMailItem
SafeMail.Item = NewMail

[SNIP]

The code runs fine on my computer, but on the intended server (where
it used to run fine) I get an error when it runs the line:

Set oMessage = oSession.GetMessage(sEntry, sStore)


The error message is:

Error Number -2147467259
The client operation failed. [Microsoft Exchange Server Information
Store - [E_FAIL(80004005)]]

Any ideas what could be wrong? I think the code is fine, so what
could have happened on the server?
 
M

Michael Bauer [MVP - Outlook]

That's not the Redemption but CDO library. Have you considered that maybe
the message doesn't exist anymore?

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6&lang=en>


Am Wed, 30 Jul 2008 14:05:43 -0700 (PDT) schrieb McKilty:
 
M

McKilty

Oops. It's been a while since I've programmed anything, so I'm very
rusty. This was actually written by a co-worker who has since left.


Ok... I've been working on it and it appears that one lone e-mail was
screwing it up. When that e-mail was removed, it worked fine. The e-
mail was there and there appeared to be nothing wrong with it.


Thanks




That's not the Redemption but CDO library. Have you considered that maybe
the message doesn't exist anymore?

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6〈=en>

Am Wed, 30 Jul 2008 14:05:43 -0700 (PDT) schrieb McKilty:
Here's a strange problem that recently popped up. I have a program
that creates an e-mail in Office 2003 via Outlook Redemption. This
program has worked for months, but suddenly it stopped working.
The applicable code is:
Dim olOutlook As Outlook.Application
Dim nsNameSpace As Outlook.NameSpace
Dim oSession As MAPI.Session
Dim mFolder
Dim itmEmails As Items
Dim iCount, iEmail, iLate, iSub As Double
Dim oItem
Dim sEntry, sStore, sSQLText, sBCC, sCC, s1Day, s2Day, sGT2Day, sBody
As String
Dim oMessage As MAPI.Message
Dim NewMail
Dim SafeMail
Set olOutlook = New Outlook.Application
Set nsNameSpace = olOutlook.GetNamespace("MAPI")
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "DS", , False, False
Set mFolder = nsNameSpace.Folders("Mailbox - Daily
Summary").Folders("DailySummaries")
Set itmEmails = mFolder.Items
Set itmEmails = itmEmails.Restrict("[ReceivedTime] < '" & Format(gDate
& " 11:59 PM", "MM/dd/yy hh:mm AMPM") & "'")
iCount = itmEmails.Count
For iEmail = 1 To iCount
Set oItem = itmEmails.Item(iCount - iEmail + 1)
sEntry = oItem.EntryID
sStore = oItem.Parent.StoreID
Set oMessage = oSession.GetMessage(sEntry, sStore)
Set NewMail = itmEmails.Item(iCount - iEmail + 1)
Set SafeMail = New Redemption.SafeMailItem
SafeMail.Item = NewMail

The code runs fine on my computer, but on the intended server (where
it used to run fine) I get an error when it runs the line:
Set oMessage = oSession.GetMessage(sEntry, sStore)
The error message is:
Error Number -2147467259
The client operation failed. [Microsoft Exchange Server Information
Store - [E_FAIL(80004005)]]
Any ideas what could be wrong? I think the code is fine, so what
could have happened on the server?
 
A

Ariel Dembling

In my experience this error appears due to Exchange being unable to find the
email in its Information Store (at least in a timely manner). I've seen this
problem *a lot* with Exchange 5.5, particularly with very old emails with
attachments. At least in my case it would eventually work after retrying long
enough. My guess is that Exchange fails to find the attachment in its store
indexes, and that after a few failed accesses to the email it launches an
asynchronous search for the attachment (probably a sequencial search) in
order to reindex it; the client operation succeeds when Exchange has
completed reindexing the attachment.

This can be a real pain when migrating hundreds of thousands of emails from
Exchange 5.5 servers (not to another Exchange, sorry), where several
thousands are stuck in this way. Retrying access manually for each mail from
an Outlook client is hopeless. Don't ask :)

If your problem also disappears with enough retries, you should handle the
error in your VBA code like this:

Sub SomeSub()
blah blah
On Error GoTo CATCH
this is the line where the error appears
On Error GoTo 0
blah blah
Exit Sub
CATCH
Resume
End Sub

Hope that helps.


McKilty said:
Oops. It's been a while since I've programmed anything, so I'm very
rusty. This was actually written by a co-worker who has since left.


Ok... I've been working on it and it appears that one lone e-mail was
screwing it up. When that e-mail was removed, it worked fine. The e-
mail was there and there appeared to be nothing wrong with it.


Thanks




That's not the Redemption but CDO library. Have you considered that maybe
the message doesn't exist anymore?

--
Best regards
Michael Bauer - MVP Outlook

: VBOffice Reporter for Data Analysis & Reporting
: Outlook Categories? Category Manager Is Your Tool
: <http://www.vboffice.net/product.html?pub=6〈=en>

Am Wed, 30 Jul 2008 14:05:43 -0700 (PDT) schrieb McKilty:
Here's a strange problem that recently popped up. I have a program
that creates an e-mail in Office 2003 via Outlook Redemption. This
program has worked for months, but suddenly it stopped working.
The applicable code is:
Dim olOutlook As Outlook.Application
Dim nsNameSpace As Outlook.NameSpace
Dim oSession As MAPI.Session
Dim mFolder
Dim itmEmails As Items
Dim iCount, iEmail, iLate, iSub As Double
Dim oItem
Dim sEntry, sStore, sSQLText, sBCC, sCC, s1Day, s2Day, sGT2Day, sBody
As String
Dim oMessage As MAPI.Message
Dim NewMail
Dim SafeMail
Set olOutlook = New Outlook.Application
Set nsNameSpace = olOutlook.GetNamespace("MAPI")
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "DS", , False, False
Set mFolder = nsNameSpace.Folders("Mailbox - Daily
Summary").Folders("DailySummaries")
Set itmEmails = mFolder.Items
Set itmEmails = itmEmails.Restrict("[ReceivedTime] < '" & Format(gDate
& " 11:59 PM", "MM/dd/yy hh:mm AMPM") & "'")
iCount = itmEmails.Count
For iEmail = 1 To iCount
Set oItem = itmEmails.Item(iCount - iEmail + 1)
sEntry = oItem.EntryID
sStore = oItem.Parent.StoreID
Set oMessage = oSession.GetMessage(sEntry, sStore)
Set NewMail = itmEmails.Item(iCount - iEmail + 1)
Set SafeMail = New Redemption.SafeMailItem
SafeMail.Item = NewMail

The code runs fine on my computer, but on the intended server (where
it used to run fine) I get an error when it runs the line:
Set oMessage = oSession.GetMessage(sEntry, sStore)
The error message is:
Error Number -2147467259
The client operation failed. [Microsoft Exchange Server Information
Store - [E_FAIL(80004005)]]
Any ideas what could be wrong? I think the code is fine, so what
could have happened on the server?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top