Sender, SenderEmailAddress Missing in Folder.Items

风流意气都作罢 提交于 2019-12-11 06:36:50

问题


I want to download attachments from Outlook emails.

Here is the code I am using to retrieve emails.

Set OutlookApp = New Outlook.Application
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set Folder = OutlookNamespace.GetDefaultFolder(olFolderInbox).Folders(botMailFolder)

i = 1

For Each OutlookMail In Folder.Items
    If InStr(OutlookMail.Subject, " ") <> 0 Then

        If OutlookMail.Attachments.Count > 0 Then

            Dim folderBase As String
            folderBase = botLocalFolder

            Dim newFolder As String
            newFolder = folderBase & OutlookMail.EntryID

            'OutlookItem.SenderAddress

            If Not FolderExists(newFolder) Then
                FolderCreate newFolder
            End If

            For Each a In OutlookMail.Attachments
                Dim newFileName As String
                newFileName = newFolder & "\" & a.DisplayName
                'MsgBox newFileName
                a.SaveAsFile newFileName
            Next

        End If

    End If

Next OutlookMail

The problem is, Sender,SenderEmailAddress and SenderName are empty. Only SenderEmailType is populated as EX.

The code is executed as an Excel macro and all my senders (users) are Exchange 2013 users.

How can I find email address and name for the sender of an email item?

Here is what I see on my locals window.

This happens for all emails in the box. Someone told me it is because all are "exchange users" and for them enterprise admins can put restrictions.


回答1:


I had this issue as well. The only way I could get past it is by running the code IN OUTLOOK VBA (Outlook -> developer tab -> vba), and do not start your application specifically as an outlook application.

example:

Dim olApp As Outlook.Application
Set olApp = CreateObject(Outlook.Application)

would need to become

Dim olApp As Application
Set olApp = Application

The trick is to NOT open a new instance of outlook from outside outlook (IE. in Excel). If you've got any type of Outlook Exchange security settings, opening outlook from excel will prohibit you from accessing key pieces of information such as sender.



来源:https://stackoverflow.com/questions/52776954/sender-senderemailaddress-missing-in-folder-items

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!