Quirk with Outlook security

R

Rob Nicholson

Can anyone help explain the following... we have an application which uses
the Outlook object model to send emails. We are therefore pretty up to speed
with Outlook securty templates and CheckAdminSettings, i.e they are enabled.

In debugging security, I created a sample VB6 app to send a test email. I
thought I was going mad in my first attempt (method #3 here) whereby nothing
I seemed to do with the security template could prevent the popup dialog
occuring when the line:

MailItem.Recipients.Add ("(e-mail address removed)")

was executed in method #3. As I knew we *could* send email, I checked the
existing code in two applications. In the first application, it created the
recipient using NameSpace.CreateRecipient. The second application, it
created the mail item in in the MAPI inbox and the added recipients in the
same way.

In both cases (methods 1 and 2), the security dialog doesn't appear -
controlled via "When accessing address information via Outlook Object Model"
switch in the template.

So I guess the question is - why does:

Dim Namespace As Outlook.Namespace
Set Namespace = OutlookApp.GetNamespace("MAPI")
Dim MailItem As Outlook.MailItem
Set MailItem = OutlookApp.CreateItem(olMailItem)
Dim Recipient As Outlook.Recipient
Set Recipient = Namespace.CreateRecipient("(e-mail address removed)")

and

Dim Namespace As Outlook.Namespace
Set Namespace = OutlookApp.GetNamespace("MAPI")
Dim Inbox As Outlook.MAPIFolder
Set Inbox = Namespace.GetDefaultFolder(olFolderInbox)
Dim MailItem As Outlook.MailItem
Set MailItem = Inbox.Items.Add
MailItem.Recipients.Add ("(e-mail address removed)")

NOT trigger the popup (i.e. the security template is acted upon) whereas:

Dim MailItem As Outlook.MailItem
Set MailItem = OutlookApp.CreateItem(olMailItem)
MailItem.Recipients.Add ("(e-mail address removed)")

DOES trigger the popup, i.e. the security template is ignored.

I'm guessing it something to do with the context in which the recipients are
added. In the working cases, this is (kind of) under the MAPI namespace
whereas the failing case, the mailitem is created directly under the
Outlook.Application.

Cheers, Rob.

' The code...

#If Method = 1 Then
Dim OutlookApp As New Outlook.Application
OutlookApp.Session.Logon , , , True
Dim Namespace As Outlook.Namespace
Set Namespace = OutlookApp.GetNamespace("MAPI")
Dim MailItem As Outlook.MailItem
Set MailItem = OutlookApp.CreateItem(olMailItem)
Dim Recipient As Outlook.Recipient
Set Recipient = Namespace.CreateRecipient("(e-mail address removed)")
MailItem.Recipients.Add Recipient
MailItem.Subject = "Testing Outlook security"
MailItem.Body = "1-2-3"
MailItem.Send
#End If

#If Method = 2 Then
Dim OutlookApp As New Outlook.Application
OutlookApp.Session.Logon , , , True
Dim Namespace As Outlook.Namespace
Set Namespace = OutlookApp.GetNamespace("MAPI")
Dim Inbox As Outlook.MAPIFolder
Set Inbox = Namespace.GetDefaultFolder(olFolderInbox)
Dim MailItem As Outlook.MailItem
Set MailItem = Inbox.Items.Add
MailItem.Recipients.Add ("(e-mail address removed)")
MailItem.Subject = "Testing Outlook security"
MailItem.Body = "1-2-3"
MailItem.Send
#End If

#If Method = 3 Then
Dim OutlookApp As New Outlook.Application
OutlookApp.Session.Logon , , , True
Dim MailItem As Outlook.MailItem
Set MailItem = OutlookApp.CreateItem(olMailItem)
MailItem.Recipients.Add ("(e-mail address removed)")
MailItem.Subject = "Testing Outlook security"
MailItem.Body = "1-2-3"
MailItem.Send
#End If

End Sub
 
R

Rob Nicholson

Hmm, further bit of madness, change method #3 (the failing one) to:

#If Method = 3 Then
Dim OutlookApp As New Outlook.Application
OutlookApp.Session.Logon , , , True
Dim MailItem As Outlook.MailItem
Set MailItem = OutlookApp.CreateItem(olMailItem)
MailItem.Subject = "Testing Outlook security"
MailItem.Body = "1-2-3"
MailItem.Recipients.Add ("(e-mail address removed)")
MailItem.Send
#End If

i.e. add the recipients AFTER setting up the subject and body and guess
what - it works, no security dialog. So WTF does it change if the add
recipients is before setting up subject and body. Tell me that!!!

Cheers, Rob.
 
R

Rob Nicholson

Can anyone help explain the following... we have an application which uses

*Cough* MSDN validation poster - isn't somebody official supposed to reply
:)

Yes, I know it's hard <grin>

Rob.
 

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