I am calling a VBS function from an intranet page, using IE 11 (yes, it has to be that browser). The function processes an Outlook mailbox, and is partly working: I can run down the list of mails and find the Subject and Body, but I need the sender's email address. I can get this in various ways when I run similar code as an Outlook macro, but none of them work in VBS - the script just hangs (no error message) when I try to get anything of interest - see the function, with various things I've tried commented. Any pointers as to where I'm going wrong gratefully received....
Function readEmails(mailbox)
Dim iCt
Set objOutlook = CreateObject("Outlook.Application")
Set NS = objOutlook.GetNamespace("MAPI")
Set olFolder = NS.Folders(mailbox)
Set olFolInbox = olFolder.Folders("Inbox")
iCt = 0
For iCt =1 to olFolInbox.Items.Count
set olMessage=olFolInbox.Items(iCt)
msgbox(ict & "-" & olMessage.Subject )
msgbox("SenderEmailType=" & olMessage.SenderEmailType)
msgbox("SenderEmailAddress=" & olMessage.SenderEmailAddress) 'hangs
'set sn=olMessage.SenderName 'hangs
set sUser=olMessage.Sender
'set sn=sUser.Name 'hangs
'msgbox(sUser) 'hangs
'set sExUser=sUser.GetExchangeUser ' hangs
End If
Next
readEmails=sReturn
End Function
It seems that a security issue takes its place when you automate Outlook from an external macro - it can be a security prompt or an exception in the code. How it is seen really depends on the Outlook version (its internal implementation). To avoid security issues when dealing with OOM you can use the following approaches:
Users get the security prompts/exceptions because Outlook is configured on the client computer in one of the following ways:
Read more about that in the Security Behavior of the Outlook Object Model article.