Forum Discussion
Is there a way to send an email with an attachment for a form submission
Hello. I couldn't find a clear answer on this. Is there a way to use power automate to send attachment(s) via email to a form sender depending on their answers on a form?
Example -
Information request
Would you like more information on dogs - ( ) yes ( ) no
Would you like more information on cats - ( ) yes ( ) no
Would you like more information on rabbits - ( ) yes ( ) no
If the person selects yes for one of the options it would send them a specific PDF via email. If they select yes for multiple options, it would send them a single email with multiple PDFs that coordinate with the questions. The PDFs are available to pull from either my one drive or share point.
1 Reply
- Rob_ElliottSilver Contributor
Yes this can certainly be done. In my form I have asked the responder to select the Caribbean country they want to visit, the airline they will use and the hotel they will stay in.
The SharePoint library with the files to be used as attachments is shown below. Make sure you add the Title metadata in which needs to be the same as the option in the form.
The flow is as follows. I've used the classic designer as I find it easier for screenshots.
1.
2. Add 3 compose actions which bring back the 3 answers from the form for use later (there are other ways to do this but I like compose actions):
3a. I have put the following actions into a scope to keep related information together and making copying the actions easier & quicker. The first get files action for the country has a filter query which is Document eq 'Island' and Title eq {outputs of the country compose}. I've then added a condition to check if any document/image was brought back. The expression for that islength(outputs('Get_files_(properties_only)')?['body/value']) is greater than 0
3b. Leave the red if no channel empty. In the green if yes channel add an apply to each and select value from the dynamic content box for the first field. Select your site and select Identifier for the File Identifier field.
Next - and still inside the apply to each - add an append to array variable. Select the variable you initialized at 1 above. and in the value field paste in the following:
{
"Name": @{items('Apply_to_each')?['{FilenameWithExtension}']},
"ContentBytes": @{body('Get_file_content')}
}
4. Copy the whole scope to your clipboard then select the copied scope from your clipboard for the airline and hotel, changing the filter query to point to the correct outputs.
5. Add another compose action and select varAttachments as the input. Then add the send an email action. In this example I've added in the country, airline and hotel that was selected in the form. Then for the attachments click the formatting icon to the right of the field. then select the outputs of the compose above.
Result
So when the form is submitted the flow runs and the email is shown below with 3 attachments based on the 3 selections made in the form.
And when another responder selects different answers the email also reflects that:
Hope that helps.Rob
Los Gallardos, Spain
Microsoft Power Platform Community Super User
Principal Consultant, Power Platform, WSP Global (and classic 1967 Morris Traveller driver)