Solved

Scanning inbox brings up Outlook security message

Posted on 2011-03-24
6
309 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
Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

758 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

14 Experts available now in Live!

Get 1:1 Help Now