Whenever you send e-mail messages in Microsoft Access, you get Outlook security warnings like A program is trying to automatically send email:
To get rid of such security warning messages, use the Outlook Security Manager that effectively disables / enables the Outlook Security. With the ActiveX edition of this product you can easily switch the Outlook security off and on. Here we describe two methods of sending emails in Microsoft Access using the ActiveX edition of Outlook Security Manager.
Sending emails using the DoCmd. SendObject method
With the ActiveX edition of Outlook Security Manager you write the following simple code:
Sub SendEmailMessageViaDoCmd() Dim SecurityManager As Object Set SecurityManager = CreateObject("AddInExpress.OutlookSecurityManager") SecurityManager.DisableSMAPIWarnings = True On Error GoTo Finally DoCmd.SendObject acSendNoObject, , ,"firstname.lastname@example.org", , , _ "Message subject", "Message body", False Finally: SecurityManager.DisableSMAPIWarnings = False Set SecurityManager = Nothing End Sub
What does this procedure do?
At first, the Outlook Security Manager object is declared and created. Then DisableSMAPIWarnings of this object is set to true. At this moment the Outlook Security Manager disables security warnings from the so-called Simple MAPI email processing protocol, which is used whenever an email is being sent. Then your familiar DoCmd creates and sends your e-mail. And finally, DisableSMAPIWarnings is set to False, enabling security warnings from Simple MAPI. Note, this last step is important, because if you fail to re-enable the Simple MAPI Security, some other MDB or ADP opened in this MS Access session can potentially do some harm to you.
Sending emails using Outlook Object Model
With the ActiveX edition of Outlook Security Manager you send emails in the following way:
Sub SendEmailMessageViaOutlookObjectModel() Dim olApp As Outlook.Application Set olApp = New Outlook.Application 'GetObject(,"Outlook.Application") Dim email As Outlook.MailItem Set email = olApp.CreateItem(olMailItem) Dim SecurityManager As Object Set SecurityManager = CreateObject("AddInExpress.OutlookSecurityManager") SecurityManager.ConnectTo olApp SecurityManager.DisableOOMWarnings = True On Error GoTo Finally email.Recipients.Add "email@example.com" email.Subject = "Message subject" email.Body = "Message body" email.Send Finally: SecurityManager.DisableOOMWarnings = False SecurityManager.Disconnect olApp Set SecurityManager = Nothing Set email = Nothing Set olApp = Nothing End Sub
How does this procedure work?
First off, you get the Outlook.Application object and the MailItem object (the last one represents an email in Outlook). Then you create the Outlook Security Manager object and connect it to the Outlook application. Then the DisableOOMWarnings of the Outlook Security object is set to true. The ‘OOM’ part in the property name stands for “Outlook Object Model”. At this moment the Outlook Security Manager disables Outlook Security prompts. Then you set the email properties, such as, Subject, Body, add email addresses to the Recipients collection and send the email. And finally, DisableOOMWarnings is set to False, enabling Outlook Security. Note, this last step is highly important, because in the other case you can leave your Outlook unprotected from really malicious software. Sure, it is not what you really want. That’s all for now. Hope this helps.
Add-in Express Team Leader