![]() |
Quirk with Outlook security
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 ") 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 = ") 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 ") 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 ") 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 = ") 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 ") 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 ") MailItem.Subject = "Testing Outlook security" MailItem.Body = "1-2-3" MailItem.Send #End If End Sub |
Quirk with Outlook security
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 ") 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. "Rob Nicholson" wrote in message ... 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 ") 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 = ") 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 ") 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 ") 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 = ") 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 ") 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 ") MailItem.Subject = "Testing Outlook security" MailItem.Body = "1-2-3" MailItem.Send #End If End Sub |
Quirk with Outlook security
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. |
All times are GMT +1. The time now is 06:49 AM. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com