Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Scanning inbox brings up Outlook security message

Posted on 2011-03-24
6
Medium Priority
?
362 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 20

Assisted Solution

by:darbid73
darbid73 earned 800 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 20

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
Office 365 Training for Admins - 7 Day Trial

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

 

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

There are times when we need to generate a report on the inbox rules, where users have set up forwarding externally in their mailbox. In this article, I will be sharing a script I wrote to generate the report in CSV format.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

722 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