Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
853 views
in Technique[技术] by (71.8m points)

excel - Sender, SenderEmailAddress Missing in Folder.Items

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. Locals window capture

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...