Solved

Scanning inbox brings up Outlook security message

Posted on 2011-03-24
6
337 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 20

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 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
How to resolve IMCEAEX NDRs in Exchange or Exchange Online related to invalid X500 addresses.
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

789 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