' Items where PR_SENDER_EMAIL_ADDRESS = specified email address ' Items where SenderEmailAddress = specified email address StrFilter = & """" & PR_SENT_REPRESENTING_EMAIL_ADDRESS & """" & " = '" & mailAddress & "'" ' Items where PR_SENT_REPRESENTING_EMAIL_ADDRESS = specified email addressĭebug.Print "PR_SENT_REPRESENTING_EMAIL_ADDRESS" Set myResults = (strFilter)ĭebug.Print " myResults.Count.: " & myResults.Count StrFilter = & """" & PR_RECEIVED_BY_EMAIL_ADDRESS & """" & " = '" & mailAddress & "'"ĭebug.Print "strFilter. ' Logical as the item in the Sent folder could have multiple receiversĭebug.Print "PR_RECEIVED_BY_EMAIL_ADDRESS" ' Items where PR_RECEIVED_BY_EMAIL_ADDRESS = specified email address ' Filtering Items Using a String Comparison MailAddress = "mailAddress: " & mailAddress Set myFolder = ActiveExplorer.CurrentFolderĭebug.Print "myFolder.: " & myFolderĭebug.Print ": " & PropertyAccessor.GetProperty(PR_SENDER_EMAIL_ADDRESS)Įxample format from Filtering Items Using a String Comparison Private Sub RestrictBySchema() PropertyAccessor.GetProperty(PR_SENT_REPRESENTING_EMAIL_ADDRESS)ĭebug.Print "PR_SENDER_EMAIL_ADDRESS.: " & _ PropertyAccessor.GetProperty(PR_RECEIVED_BY_EMAIL_ADDRESS)ĭebug.Print "PR_SENT_REPRESENTING_EMAIL_ADDRESS: " & _ PropertyAccessor.GetProperty(PR_SENT_REPRESENTING_NAME)ĭebug.Print "PR_RECEIVED_BY_EMAIL_ADDRESS.: " & _ PropertyAccessor.GetProperty(PR_RECEIVED_BY_NAME)ĭebug.Print "PR_SENT_REPRESENTING_NAME.: " & _ Set propertyAccessor = oItem.propertyAccessorĭebug.Print "oItem.Parent.: " & oItem.Parentĭebug.Print "Sender Display name.: " & oItem.Senderĭebug.Print "Sender address.: " & oItem.SenderEmailAddressĭebug.Print "PR_RECEIVED_BY_NAME.: " & _ ' select an item from any folder not the Sent folder Option ExplicitĬonst PR_SENT_REPRESENTING_NAME As String = ""Ĭonst PR_RECEIVED_BY_EMAIL_ADDRESS As String = ""Ĭonst PR_SENT_REPRESENTING_EMAIL_ADDRESS As String = ""Ĭonst PR_SENDER_EMAIL_ADDRESS As String = ""ĭim propertyAccessor As outlook.propertyAccessor The usefulness is still to be proven as the values from the the address-related properties are either not available or trivial. Read MAPI properties not exposed in Outlook's Object Model You can get to what appears to be "urn:schemas:httpmail:to" another way. The cells A2:A4 in Sheet1 contain email address such as for instance. ' At least one reply setting is required in order to replyall to fireĬustomMailItem.Body = "Just a reply text " & customMailItem.Body Set customMailItem = outlookResults.Item(resultItem).ReplyAll ' Some properties you can check from the email item for debugging purposesĭebug.Print outlookResults.Item(resultItem).SentOn, outlookResults.Item(resultItem).ReceivedTime, outlookResults.Item(resultItem).SenderName, outlookResults.Item(resultItem).Subject If outlookResults.Count = 0 Then Exit Sub Set outlookResults = outlookSearch.Results ' Wait until search is complete based on outlookApp_AdvancedSearchComplete event Set outlookSearch = OutlookApp.AdvancedSearch(searchFolderName, searchString, searchSubFolders, "SearchTag") SearchString = "urn:schemas:httpmail:to like '" & emailSubject & "'" ' You can look up on the internet for urn:schemas strings to make custom searches ' Variable defined at the class level (modified by outlookApp_AdvancedSearchComplete when search is completed) Sub SearchAndReply(emailSubject As String, searchFolderName As String, searchSubFolders As Boolean) 'MsgBox "The AdvancedSearchComplete Event fired." Private Sub outlookApp_AdvancedSearchComplete(ByVal SearchObject As Search) In a class module named clsOutlook: Option Explicitĭim WithEvents OutlookApp As Outlook.Application Set searchRange = ThisWorkbook.Worksheets("Sheet1").Range("A2:A4")Ĭall oOutlook.SearchAndReply(subjectCell.Value, searchFolderName, False) SearchFolderName = "'" & (olFolderInbox).FolderPath & "','" & (olFolderSentMail).FolderPath & "'" ' Get the outlook inbox and sent items folders path (check the scope specification here: ) Set testOutlook = GetObject(, "Outlook.Application") ' Start outlook if it isn't opened (credits: ) In a VBA module: Public Sub ProcessEmails() What is the urn:schemas to search for the email address of the sender and receiver in my Outlook Inbox and Sent Items? With searchString = "urn:schemas:httpmail:to like '" & emailSubject & "'" I replaced searchString = "urn:schemas:httpmail:subject like '" & emailSubject & "'" I would like to search for the latest email I received or sent to a specific email address as opposed to search by subject.
0 Comments
Leave a Reply. |