Solved

Scanning inbox brings up Outlook security message

Posted on 2011-03-24
6
321 Views
Last Modified: 2012-05-11
I have an Access database that needs to scan through a inbox subfolder to read the "SenderEmailAddress" information.  After a lot of good help (and persistence) from BlueDevilFan, we ended up with the following code, which worked a treat.  However, it comes up with the Outlook Security message, which I need to get rid of.

Originally we linked into email sub-folders through ADO, which looked ideal - but the ADO object does not present the "SenderEmailAddress".

Unfortunately, we cannot use any third party products for this fix - so any suggestions would be greatly appreciated.
Sub ReadBounced()

    Dim olkApp As Object, olkSes As Object, olkFld As Object, olkMsg As Object
    Set olkApp = CreateObject("Outlook.Application")
    Set olkSes = olkApp.GetNamespace("MAPI")    
    olkSes.Logon
    Set olkFld = olkSes.GetDefaultFolder(6).Folders("00 Technical").Folders("Bounced emails")
    For Each olkMsg In olkFld.Items
        With olkMsg
            Debug.Print .SenderEmailAddress
        End With
    Next
    Set olkMsg = Nothing
    Set olkFld = Nothing
    olkSes.Logoff
    Set olkSes = Nothing
    Set olkApp = Nothing
    
End Sub

Open in new window

0
Comment
Question by:Andy Brown
  • 3
  • 2
6 Comments
 
LVL 19

Assisted Solution

by:darbid73
darbid73 earned 200 total points
ID: 35205532
I think one of the best resources of information about Outlook / books / Your Security Question is Outlook Code - here

Now there are many many different solutions to this problem and I do not intend to list them all. You are obviously aware of 3rd party ones as well which you have ruled out.

Once you understand why you get the security prompt you will understand my next statements:

If you get your outlook object from Outlook itself when outlook starts and you then use this object for any code, you will not get a security prompt.  To put that in paractical terms, if you take your code - remove the CreateObject - and put it into Outlook itself then you will not get the prompts.

Thus my suggestion is that you let us know more about your structure of communication between Access and outlook and if you for example have to distribute this to lots of people or not.  I am heading toward you making an addon or something like that yourself or just coding in Outlook if distribution is not a problem.  Outlook code can commuicate with Access code and vica-versa - and Outlook can also write directly to your database with DAO or ADO if you want.
0
 

Author Comment

by:Andy Brown
ID: 35205558
Thank you for that very useful response - makes a lot of sense (especially the add-on route).  I'm going to take a closer look at that first and then see where we are.

Thanks again.

0
 
LVL 19

Expert Comment

by:darbid73
ID: 35205612
The addon route is a nightmare.  I am still trying to understand it with Visual Studio and .NET.  If you can find a Visula Basic 6 version laying around I am better at making a COM addon from it. Although this is a really old way of doing things these days.

In my opinion your first step is what code can you move over to Outlook.  Outlook has a VBeditor too and you can code there as well.  Once you get the code working how you like then you can look at the distribution issue.  If it is only a couple of computers then you could just add the code to their computer, but if it major then you have to look at addons again.

I am sure BDF will be along with suggestions as well.
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:Andy Brown
ID: 35205622
Thank you - due to the number of machines running this, I think an Add-on is the way to go, but I am still looking into it.
0
 
LVL 10

Accepted Solution

by:
conagraman earned 300 total points
ID: 35217330
this is what i use

'------needs a reference to Microsoft Outlook 12.0 object library
On Error Resume Next

Dim Olook As Outlook.Application
Dim oNs As Outlook.NameSpace
Dim oFldr As Outlook.MAPIFolder
Dim OMail As Outlook.MailItem
Dim LookFor As String

Set Olook = New Outlook.Application
Set oNs = Olook.GetNamespace("MAPI")
Set oFldr = oNs.GetDefaultFolder(olFolderInbox)   '/////////////  mailbox

For Each OMail In oFldr.Items
        With OMail
       
           MsgBox (.SenderEmailAddress)  '//////////do something

        End With
Next OMail
         
    Set OMail = Nothing
    Set oFldr = Nothing
    Set oNs = Nothing
    Set Olook = Nothing
0
 

Author Closing Comment

by:Andy Brown
ID: 35217369
Thanks guys - that's really good information.

All the best.
0

Featured Post

Integrate social media with email signatures

Is your company active on social media? Do you also use email signatures? Including social media icons in your email signature is a great way to get fans for free. Let all your email users know you’re on social media quickly and easily, in a single click.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
Are you unable to connect or configure Hotmail email account in Microsoft Outlook 2010, 2007? Or Outlook.com emails are not downloading to Outlook? Lets’ see the problem and resolve Outlook Connector error syncing folder hierarchy (0x8004102A).
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now