Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to access a message body in a rule (vba)

43 views
Skip to first unread message

chuck rudolph

unread,
Apr 14, 2005, 8:43:01 PM4/14/05
to
I have a vb routine that works except for one security issue. When the rule
is run it triggers a message box that says "A program is trying to access
e-mail addresses you have stored in Outlook. Do you want to allow this?" If I
choose to allow this, all is well for 10 minutes (the max). It looks to be
"by design", but then again in a thread back on 10/31/2004, Sue says "If your
objects all derive from Outlook 2003 VBA's intrinsic Application object, you
should receive no security prompts. Signing the macro will have no effect."

I get the prompt when my code attempts to read the message body. (I'm
reading it in HTML in the example below, but a text read gets the same
error.) It's line two below:

Sub PrintBodyRule(Item As Outlook.MailItem)
Dim messageBody As String
messageBody = Item.HTMLBody
.
.
End Sub

So the question is "should a vb be able to read Item.HTMLBody without
getting this security warning, when the vb code runs as a RULE script?"

The project is signed. I have tried various (macro) security settings. My
outlook version is 2003, SP1.

The full rule's reason to live is to print ONLY the body of a message. A
macro works just fine when I open up a mail message and run it from the tools
menu. In that case I use Outlook.ActiveInspector.CurrentItem.HTMLBody to
access the body.

If anyone wants a copy of the code, shoot me an email and I will send it off
or post it.

Thanks...Chuck

Sue Mosher [MVP-Outlook]

unread,
Apr 14, 2005, 10:39:49 PM4/14/05
to
In theory, it should, but in practice it doesn't. The MailItem argument apparently isn't "trusted" with regard to the object model guard. Recoding with Redemption or Express ClickYes may be the easiest solution (besides living with the prompts).

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"chuck rudolph" <chuckr...@discussions.microsoft.com> wrote in message news:C3FD6018-5A7B-46DC...@microsoft.com...

Michael Bauer

unread,
Apr 15, 2005, 1:05:26 AM4/15/05
to
Hi Chuck,

if the MailItem has its EntryID already then you could use the
following:

Sub PrintBodyRule(Item As Outlook.MailItem)
Dim oMail as Outlook.MailItem
Dim messageBody As String
Set oMail=Application.Session.GetItemFromID(Item.EntryID)
messageBody = oMail.HTMLBody

--
Viele Grüße
Michael Bauer - MVP Outlook


"chuck rudolph" <chuckr...@discussions.microsoft.com> wrote in
message news:C3FD6018-5A7B-46DC...@microsoft.com...

Sue Mosher [MVP-Outlook]

unread,
Apr 15, 2005, 8:27:14 AM4/15/05
to
That's too easy! A wonderful workaround, Michael!

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Michael Bauer" <mi...@t-online.de> wrote in message news:%23ky6srX...@TK2MSFTNGP09.phx.gbl...

chuck rudolph

unread,
Apr 16, 2005, 2:59:03 PM4/16/05
to
Michael (& Sue) --The workaround worked just peachy. Since in my case, the
item is a received item in the inbox it will always have an EntryID and the
solution always work.

Now, can either of you explain why the "simple" [Item.HTMLBody] approach
causes the dialogbox to appear, whereas the "complex" [Michael's two lines
below] approach does not?


Thanks...Chuck

"Michael Bauer" wrote:

> Dim oMail as Outlook.MailItem
> Set oMail=Application.Session.GetItemFromID(Item.EntryID)
>
> Dim messageBody As String
> messageBody = oMail.HTMLBody
>

Michael Bauer

unread,
Apr 17, 2005, 3:36:12 AM4/17/05
to
Hi Chuck,

obviously the MS developers have decided that the MailItem argument
shouldn´t be trusted. On the other hand all Items accessed via the
intrinsic Application object *are* trusted (since OL 2003).

I.e. you need the reference returned from the intrinsic Application
object and the event´s argument isn´t from.

--
Viele Grüße
Michael Bauer - MVP Outlook


"chuck rudolph" <chuckr...@discussions.microsoft.com> wrote in

message news:D031EFEC-B2F0-4F44...@microsoft.com...

Sue Mosher [MVP-Outlook]

unread,
Apr 19, 2005, 9:51:29 AM4/19/05
to
It's specifically the HTMLBody property that is now considered subject to address book security prompts because message bodies so often contain personal contact information.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Michael Bauer" <mi...@t-online.de> wrote in message news:uRKP8gyQ...@tk2msftngp13.phx.gbl...

0 new messages