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
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