cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate I
Advocate I

Send Email with Multiple Attachments

I built a flow that would get attachments from SharePoint and append to an Array to use to send multiple attachments.

I followed the set of instructions using this link https://flow.microsoft.com/en-us/blog/multiple-attachments-single-email/.

Now the flow is working, however, instead of sending one email, it seems to be sending an email per attachment, so if I have 3 attachments it will send 3 emails, and sometimes attaching the same documents 2 or 3 times in the same email.

Could you please tell me what I'm doing wrong?

 

Thank you!

 

 

11223344556677

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Dual Super User III
Dual Super User III

Hi!

 

 

the 1st Apply to each is to save attachments from Forms to SharePoint using this model: 

https://www.youtube.com/watch?v=IDW3ikTHu9U

 

So, if the 'Send an email' is inside this 1st 'Apply to each' and you have 2 attachments, 1st Apply to Each will iterate 2 times, and you will send two emails instead of one

 

2nd Apply to each I used was to be able to calculate a difference between 2 dates, following that model: https://powerusers.microsoft.com/t5/Building-Flows/Flow-to-calculate-elapsed-days-since-List-item-mo...

 


Now, you have a 2nd Apply to Each inside the first Apply to Each. If 'Send an email' is inside this 2nd 'Apply to each' also, an assuming 2 attachments, you will not send 2 emails, but 2 multiplied by N emails, being N the number of iterations of 2nd 'Apply to each'

 

If your goal is to send a single email, move 'Send an email' outside all these nested 'Apply to each'

Hope this helps

 

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

11 REPLIES 11
Highlighted
Dual Super User III
Dual Super User III

Hi!
The problem is, 'Send an email' is currently inside several nested Apply to each. You need to find the way to move it outside all of them in order to get a single email sent.
Hope this helps


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted

@efialttes Thank you!

Do you know how this could be done when you have so many dependencies?

The only thing I can think of is create a separate flow for the email portion. Is there any better way to do that?

Highlighted

Hi @alberto1,

 

@efialttes is correct, you should put the send Email out of the Get attachments loop. After all attachments appended, send the Email.

In case of same attachment will be sent multiple times, after a loop to Append to Array variable and Send Email, you should empty the array variable by using Set variable action to set it to Null:

Annotation 2020-04-10 163619.png

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Highlighted
Dual Super User III
Dual Super User III

@alberto1 

You are handling at least 4 nested 'Apply to each' in the same flow, right? If so, if I were you I would review the current design to check if you can remove innecesary 'Apply to each'

 

For example, on the screenshots you shared I've seen 'Get items' outputs assigned as input to an 'Apply to each' that when executed  iterates over a single item. IF you implemented such aproach to always get a single item from your Sharepoint list, then:

-either you can replace these two action blocks and use 'Get item' instead, or

-you can use first() or last() expression to handle the single result from 'Get items' outputs, meaning you do not need the 'Apply to each' anymore

 

I cannot recommend any other specific simplification approach to your current flow, since the screenshots shared are fragmented so it's hard to understand the overall goal you want to achive with flow implementation

Ánimo!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted

@efialttesand @v-litu-msft  Thank you for your suggestions! 

I'm still kind of new to flow design, but the 1st Apply to each is to save attachments from Forms to SharePoint using this model: 

https://www.youtube.com/watch?v=IDW3ikTHu9U

 

2nd Apply to each I used was to be able to calculate a difference between 2 dates, following that model: https://powerusers.microsoft.com/t5/Building-Flows/Flow-to-calculate-elapsed-days-since-List-item-mo...

 

And the 3rd Apply to each (here Apply to each 4) is to add multiple attachments to an email using the following model:

https://flow.microsoft.com/en-us/blog/multiple-attachments-single-email/

 

If there's a better way to combine all three in your opinion, please let me know!

 

Thanks again!

 

Highlighted
Dual Super User III
Dual Super User III

Hi!
"And the 3rd Apply to each (here Apply to each 4) is to add multiple attachments to an email"
So... do you really need this Apply to Each nested, i.e. inside other 'Apply to Each'?
Hope this helps


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Highlighted

@efialttes Actually the "Send an email" item is outside of "Apply to each 4" as can be seen below.

It is just so it collects all the attachments and stores it in the array. Do you think I should remove it nevertheless? I don't think it should affect the number of emails sent though, would it?

 

 

Flow8.PNG

 

Thank you!

Highlighted

@efialttes @v-litu-msft  I am not sure the problem is "Apply to each"; it seems related to the number of attachments that are being loaded in SharePoint. Could it be a time lag and loading time issue? I just re-tested it, so if I attach only 1 file, I get 1 e-mail which is fine. If I attach 2 files, I get the 1st e-mail with 1 attachment, and a second e-mail with 2 attachments. Now if I attach 3 files, I get 1 e-mail with 1 attachment, the second with 2 attachments, and the third with 3 attachments. In addition I get the emails in the same order of the loaded attachments; i.e. the first attachment loaded is coming first, then the first and second, then first second and third, etc.

 

Do you still think it's an  "Apply to each" issue?

 

Thanks!

Highlighted
Dual Super User III
Dual Super User III

Hi!

 

 

the 1st Apply to each is to save attachments from Forms to SharePoint using this model: 

https://www.youtube.com/watch?v=IDW3ikTHu9U

 

So, if the 'Send an email' is inside this 1st 'Apply to each' and you have 2 attachments, 1st Apply to Each will iterate 2 times, and you will send two emails instead of one

 

2nd Apply to each I used was to be able to calculate a difference between 2 dates, following that model: https://powerusers.microsoft.com/t5/Building-Flows/Flow-to-calculate-elapsed-days-since-List-item-mo...

 


Now, you have a 2nd Apply to Each inside the first Apply to Each. If 'Send an email' is inside this 2nd 'Apply to each' also, an assuming 2 attachments, you will not send 2 emails, but 2 multiplied by N emails, being N the number of iterations of 2nd 'Apply to each'

 

If your goal is to send a single email, move 'Send an email' outside all these nested 'Apply to each'

Hope this helps

 

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

Highlighted
Advocate I
Advocate I

Thank you @efialttes and @v-litu-msft!

 

I was able to make it work thanks to your suggestions. I had to add a few steps, but was at least able to get the Send e-mail out of all the "Apply to each" as per below:

 

 

WorkingFlow1.PNG

 

 

 

WorkingFlow2.PNG

Highlighted
Dual Super User III
Dual Super User III

HURRAY!
IT WORKS!
I've seen you marked this topic as solved. Thanks for your kindness!
This way other community members facing this same problem in the future have the chance to find a solution faster.

Thanx for your contribution to keep this community great!


Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Users online (7,395)