Problem using Outlook Redemption VBA code


B

bainsworld

I use Google for Applications to manage my email and have two domains
that receive email. When I retrieve new mail into Outlook it all
comes under the one email account. What I wanted to do was change the
account for mail from to my personal email so that when I reply to it,
it defaults to the right account (different sending email address,
signature etc).

Outlook Redemption looked great as I can access the Account whereas
the normal Outlook Object Model doesn't permit access to that in
Outlook 2003. I have a Inbox Rule that runs before all other rules
and looks for mail with "bainsworld" in the message header - this
causes the following to run:

Sub SetBainsworldAccount(inpItem As MailItem)

Dim Session As Redemption.rdoSession
Dim Account As Redemption.RDOAccount
Dim Item As Redemption.RDOMail

Set Session = New Redemption.rdoSession
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
Set Account = Session.Accounts("bainsworld")
Set Item = Session.GetMessageFromID(inpItem.EntryID)
Item.Account = Account
Item.Save

End Sub

However whilst this rule works perfectly when I manually run it, it
doesn't work when run automatically. There is no error generated in
the rule, it just doesn't seem to work. Any ideas?
 
Ad

Advertisements

D

Dmitry Streblechenko

Does any other rule touch the same item?
The problem might be a conflict between inpItem and Item (they both refer to
the same message).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
B

bainsworld

Yes, there is another rule that moves the item to a folder. Are rules
run asynchronously - I had thought they were sequential. Should I
incorporate all the preferred actions into the code as well? That is
not as flexible as using rules but if it gets the job done I might
have to live with it.

By the way, thanks for your great work with Redemption!

Regards,
Wazza
 
B

bainsworld

Actually there are a number of rules that operate on the message - the
first rule contains my "run a script" option. Perhaps I should make
it an event that runs when I hit the reply button - is that possible?
 
B

bainsworld

Except that I would already have decided which account and don't want
to change it.

I experimented with some other things and the problem I am running
into is that trying to change a field for a message during an event
does not get reflected in the main window after the event has finished
(e.g. on opening a new Inspector) unless you force Outlook to refresh
its cache (I suppose) by closing the message, going into another
folder and then returning and opening the message again. Then it
reflects the changes I made.

Is this an insurmountable problem? I tried using your MAPIUtils
object and making a call to HrSetOneProp with bSave set to TRUE and it
works but not until you force Outlook to refresh its view of the
item. Most of the examples I see are about setting properties for
items that have been created in the code and are then saved. When
these are opened in the main Outlook window then they will reflect
what has been done. I haven't seen any examples for modifying
properties "on the fly" which is what I want to do. Unless I can
think of a way to do the work whilst Outlook is occupied with other
things, as it were (I used to call that 'batch processing').

Any ideas?
 
Ad

Advertisements

D

Dmitry Streblechenko

That is a well know Outlook limitation - it cannot see changes made with
Extended MAPI until the item in question is completely dereferenced and
reopened.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
B

bainsworld

OK Dimitry, thanks for your help. It's back to the drawing board for
me but I've learnt a few things along the way.

Regards,
Wazza
 
Ad

Advertisements

B

bainsworld

Well I have my process working now in what seems to be a reliable
manner. I have actually inserted my checking and account reset in the
Application NewMailEx event. This doesn't seem to suffer from the
update conflict that was happening when I was using Rules or when an
item was opened (through the Inspector events). I guess that Outlook
has done its thing with a MailItem by the time my code gets run.

Interestingly, although the documentation says that EntryID changes
when an item is moved to a different folder, for example by a Rule, in
my configuration which is standalone Outlook, that isn't the case so I
assume that it only changes if the Folder is in a different Store.

Regards and thanks for all your help Dimitry.

Wazza
www.bainsworld.com
 

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

Top