web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Grab Attachment from a...
Power Automate
Answered

Grab Attachment from an email received 7 days earlier

(2) ShareShare
ReportReport
Posted on by 79
I'm currently working on building a flow that will locate a specific email I received 7 days ago, grab the attachment, and then upload/rename it to a SharePoint folder.
 
I have numerous flows already set up that are triggered by emails being received and then the attachment is uploaded to SharePoint, but for whatever reason this version of the flow is giving me issues...seemingly with the Get Attachment V2 and Create File actions, which should be the easiest piece of this whole process. It seems like when I add these actions there are extra Apply To Each conditions added and I can't see the File Content dynamic content as I would expect either.
 
When I test/run the flow, it says it works with no issues and every step takes less than a second...but no file is uploaded so it's definitely not working.
 
I'm open to alternative solutions to the problem statement as well...overall goal is to get these older emails with data reports so the attachment can be put into a SharePoint that is used to store various data reports used in power query automations.
 
Anyways, here's what the flow looks like with text/screenshots with any PII redacted. Appreciate any help!
 
  1. Trigger = Scheduled Recurrence at 8 AM Daily
  2. Compose = Expression to calculate 7 days prior to today. formatDateTime(addDays(utcNow(), -7), 'yyyy-MM-dd')
  3. Get Emails V3 with the subject filter added and the following Search Query.
  4. subject eq 'REDACTED SUBJECT' and receivedDateTime ge '@{formatDateTime(addDays(utcNow(), -7), 'yyyy-MM-dd')}T00:00:00Z' and receivedDateTime lt '@{formatDateTime(addDays(utcNow(), -6), 'yyyy-MM-dd')}T00:00:00Z'
  5. ​​​​​​​​​​​​​​Initialize Variable = String to rename the attachment in the uploaded destination
  6. Get Attachment V2 = I select Message ID and it gets nested in an Apply To Each automatically that populates Value of Get Attachment in the output. I then select Attachment ID which triggers another automatic Apply To Each nesting, putting Current Item of the first Apply To Each condition into the output of the new Apply to Each condition.
  7. Create File = Upload the attachment with the name defined in Initialize Variable. One I populate the File Name, this also gets nested in an Apply To Each.
 
 
Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,963 Moderator on at
     
    The issue is this, you are looping through 1-M emails, so you have your apply,
    But each email could have multiple attachments, so when you try to grab an attach with Get Attachment, it has no idea which one to grab, so you have to do this
     

    If these suggestions help resolve your issue, Please consider Marking the answer as such and also maybe a like.

    Thank you!
    Sincerely, Michael Gernaey
  • FlowingBuckle Profile Picture
    79 on at
     
    Thank you for the suggestion. I think it's getting me closer, but I'm still not there yet.
     
    For some added context...the email always has the same subject line, always includes one attachment, and is received on business days.
     
    Here is the updated Get Attachment nest that you recommended...I believe I set it up correctly.
     
    The Message Id Current item = items('Apply_to_each_-_Email')
     
    The Attachment Id Current item = items('Apply_to_each_-_Attachment')
     
     
     
    Here is another screenshot of where the error may actually be happening. The Get Emails V3 action is showing as a successful run, but it doesn't look like the Output of the action is actually getting anything.
     
     
    Here is the raw output if that helps as well:
     
    {
        "statusCode"200,
        "headers": {
            "Cache-Control""no-store, no-cache",
            "Pragma""no-cache",
            "Transfer-Encoding""chunked",
            "Set-Cookie""ARRAffinity=6f9b364d683ca411aa5ade1fdc31fce31b5778b084484877a39ee8b677ad11ad;Path=/;HttpOnly;Secure;Domain=office365-usgt.azconn-gcc-usgt-001.p.azurewebsites.us,ARRAffinitySameSite=6f9b364d683ca411aa5ade1fdc31fce31b5778b084484877a39ee8b677ad11ad;Path=/;HttpOnly;SameSite=None;Secure;Domain=office365-usgt.azconn-gcc-usgt-001.p.azurewebsites.us",
            "Strict-Transport-Security""max-age=31536000; includeSubDomains",
            "x-ms-request-id""f7b47f9a-8737-4443-aa93-790179ec250d",
            "X-Content-Type-Options""nosniff",
            "X-Frame-Options""DENY",
            "x-ms-environment-id""default-5076c3d1-3802-4b9f-b36a-e0a41bd642a7",
            "x-ms-tenant-id""5076c3d1-3802-4b9f-b36a-e0a41bd642a7",
            "x-ms-dlp-re""-|-",
            "x-ms-dlp-gu""-|-",
            "x-ms-dlp-ef""-|-/-|-|-",
            "Timing-Allow-Origin""*",
            "x-ms-apihub-cached-response""true",
            "x-ms-apihub-obo""false",
            "Date""Fri, 26 Sep 2025 16:59:51 GMT",
            "Content-Type""application/json; charset=utf-8",
            "Expires""-1",
            "Content-Length""12"
        },
        "body": {
            "value": []
        }
    }
     
     
    I appreciate your quick response and attention to this! I'll get there eventually.
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,963 Moderator on at
    Hi @FlowingBuckle

    Ok :-) with an understanding I already answered your question. So please mark that.
     
    As you are now asking a completely different question.
     
    Click the Show More and use the Subject Filter Property instead of typing it where you are
     
     
     
    If these suggestions help resolve your issue, Please consider Marking the answer as such and also maybe a like.

    In this case both of them please

    Thank you!

    Sincerely, Michael Gernaey


     
  • FlowingBuckle Profile Picture
    79 on at
    @Michael E. Gernaey Not to be pedantic, but neither response solved my issue. I am still not able to grab the email with the attachment from 7 days prior and upload it to the chosen SharePoint. I have been using the subject filter with the exact subject text in the email, and that is what gave me the output I posted below. The subject filter is also visible in the original post; it is redacted but I can assure you that piece of the flow was done correctly.
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,963 Moderator on at
     
    So let's separate things out
     
    1. Originally your flow was wrong regardless because you were not treating the loops properly. That's separate from your filtering issue.
    2. You want to filter based on having an attachment and having the Subject of X
    3. You want to do it 7 days before (For this also I meant to mention), 
     
    #1 is different from #2+#3. which I answered for initially as 2 and 3 don't mean much with 1 being wrong.
     
    Let me also mention that Get Emails Sucks... Using Graph API is way better. But I will table that.
     
    as for #3 you are doing the filter wrong as its not OData it should look like this 
    received > 2025-09-01T00:00:00Z AND received < 2025-09-01T23:59:59Z
     
    So when you build your formatDateTime its fine, but use received > and received <
    and no single quotes around the dates 
    and I do not know why you were doing -6 if you just want the one day.

    If these suggestions help resolve your issue, Please consider Marking the answer as such and also maybe a like.

    Thank you!
    Sincerely, Michael Gernaey
     
     
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,963 Moderator on at
     
    Sorry skipped #2
     
    Use the Sub Filter in my example I just hard coded 1
    With my Search Query and Subject Filter I get exactly one back
    If I want to also add with attachments etc I can, I just didn't in this example, but it works fine
    That should answer all your questions and issues
     
     
     
  • Verified answer
    FlowingBuckle Profile Picture
    79 on at
    Wanted to make this post as I did find a solution to my issue. While I'm sure someone who's better with Power Automate and JSON could have leveraged the solutions provided by @Michael E. Gernaey, unfortunately despite my numerous attempts I was not able to have the Get Email action properly locate the specific email I was looking for.
     
    My solution was to take my existing flows that are triggered when an email arrives and add a delay to them. So for example, I already have a flow set up that grabs "Data Report X" from today and uploads it to a SharePoint folder. The new flow is for "Data Report X - 7" and is the exact same flow except after the Attachment is grabbed, there is a delay of 7 days.
     
    On the one hand, this does result in numerous flows running for extended periods of time, but on the other hand...it works! The flow has triggered each day and continues to run in the background until the delay elapses, and then the flow finishes in less than 10 seconds and the desired report minus 7 days is renamed and placed in the appropriate SharePoint folder so I can then leverage it for my various Power Query based reports.
     
    I appreciate the suggestions provided and hope they may be able to help someone else in a similar issue, but I'm glad I was able to figure out my own solution as inefficient as it may be.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 801

#2
Valantis Profile Picture

Valantis 602

#3
Haque Profile Picture

Haque 581

Last 30 days Overall leaderboard