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.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…