Filter outlook sent items in vba failing for emails with multiple recipients

0 votes

I'm trying to filter delivered items in Excel depending on the recipient's email address. See the prior effort for the first part of this challenge, which is successful if there is only one recipient listed in the "TO" section.

Nevertheless, when there are two receivers on the email, filter 3 below frequently fails to detect delivered items. The first address of the two recipients in the outlook email is the one I'm filtering for.

Any ideas on how to also gather emails sent with person X's email address in the "TO" field but with additional recipients? And why did it start out failing?

Sirname = "Smith"
emailStr = "John.Smith@gmail.com"

    filter2 = "@SQL= http://schemas.microsoft.com/mapi/proptag/0x0E04001F" & " LIKE '%" & SirName & "%'"
    filter3 = "@SQL= http://schemas.microsoft.com/mapi/proptag/0x0E04001F" & " LIKE '%" & emailStr & "%'"

    Set olSentFldrItems = olSentFldr.Items.Restrict(filter2)
        
    Set olSentFldrItems2 = olSentFldr.Items.Restrict(filter3)

This results in olSentFldrItems being empty though sadly in this scenario, and also SirName filter did not pick up this particular email in my sent items.
the suggested answer results in this error

enter image description here

Feb 21, 2023 in Others by Kithuzzz
• 38,000 points
795 views

1 answer to this question.

0 votes

The PR DISPLAY TO parameter provides a list of display names (which may or may not include an address), not SMTP addresses, therefore there is no assurance that the email address will even be there.

On the Extended MAPI level (C++ or Delphi), you'd need to create a subrestriction (RES_SUBRESTRICTION) on PR_MESSAGE_RECIPIENTS that contains RES_CONTENT restriction on PR_EMAIL_ADDRESS / FL_SUBSTRING | FL_IGNORECASE.

If using Redemption (I am its author) is an option, it creates a recipient subrestriction if you specify Recipients (or To/CC/BCC) in a query:

set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set olSentFldr = Session.GetDefaultFolder(olFolderSentMail)
emailStr = "John.Smith@gmail.com"

filter = "Recipients LIKE '%" & emailStr & "%'"
Set olSentFldrItems = olSentFldr.Items.Restrict(filter)
answered Feb 21, 2023 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
1 answer
0 votes
1 answer

Error: No toolchains found in the NDK toolchains folder for ABI with prefix: llvm

Over two years has passed, now and ...READ MORE

answered Feb 11, 2022 in Others by Soham
• 9,710 points
3,146 views
0 votes
0 answers

How implement SEO (Metatags) in Angular 2 (with Angular universal for rendering on server side)?

I'm searching a fully working example about ...READ MORE

Feb 21, 2022 in Others by Kichu
• 19,040 points
795 views
0 votes
1 answer

How to use next-seo for setting nextjs meta tag with multiple OGP images?

https://github.com/garmeeh/next-seo use this git repo that contains ...READ MORE

answered Feb 24, 2022 in Others by narikkadan
• 63,600 points
6,158 views
0 votes
1 answer

VBA How to extract the date and time of arrival of a answered email

Use MailItem.ReceivedTime property. I hope this helps you ...READ MORE

answered Jan 9, 2023 in Others by narikkadan
• 63,600 points
2,914 views
0 votes
1 answer

Export Attachment from outlook to excel cells

You will need to save the attachment ...READ MORE

answered Apr 3, 2023 in Others by narikkadan
• 63,600 points
574 views
0 votes
1 answer

Embed picture in outlook mail body excel vba

The image needs to be added and ...READ MORE

answered Dec 16, 2022 in Others by narikkadan
• 63,600 points
5,496 views
0 votes
1 answer

Error populating email body from word documents

There is no need to use late ...READ MORE

answered Jan 15, 2023 in Others by narikkadan
• 63,600 points
1,568 views
0 votes
1 answer

VBA code help - Add a line for each missing date with the start and end date defined in a cell

Try this: Sub FillDates() Dim ...READ MORE

answered Jan 24, 2023 in Others by narikkadan
• 63,600 points
1,013 views
0 votes
1 answer

How implement SEO (Metatags) in Angular 2 (with Angular universal for rendering on server side)?

https://github.com/angular/universal-starter follow this repo among it there ...READ MORE

answered Feb 22, 2022 in Others by narikkadan
• 63,600 points
1,125 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP