cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

Email with attachment

Hi,

 

I need some help.Smiley Sad

 

How can i add file attachments so I can email it via a button (OnSelect) in my form.

DataCardValue16 is a Attachment field. 

 

I did something like this, but it is not the correct code...

 

Office365.SendEmail("abc@def.com","Subject","EmailBody",{Attachments:Table(DataCardValue16.Attachments,"Value","FileContent"})

 

Thanks for the help.

Adam

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Super User
Super User

Re: Email with attachment

@Anonymoushere is the dilema.

When you are dealing with a datacard attachment object, it is missing some of the pieces that it needs to get back to the data.  Keep in mind, when you send email like this, PowerApps has to download the content bytes from the SharePoint and then attach.  

I'll say up-front - if you want to skip the download to send (which could pause your App for a long time depending on the size of the attachments) then look to Flow.  You can easily get content bytes and add multiple attachments through Flow - and it's much faster as you're not limited by the bandwidth of your device you're running PowerApps on. 

 

Now with that said - You can't use the DataCard.Attachments - it is missing key columns needed to get to the data.  You can't use the Form.Updates.Attachments - it is empty (unless you're adding attachments and they've not been submitted).

 

SO - you need to go back to the source.  Let's say your form is getting its Item from a Gallery1.  Typical Item for your form would be Gallery1.Selected.

Ok - so, in this case we CAN go back to the Gallery and we WILL have the information necessary to complete the next step.

AND THAT IS - 

   Office365.SendEmail("abc@def.com","Subject","EmailBody",
{Attachments:AddColumns(Gallery1.Selected.Attachments, "Name", DisplayName, "ContentBytes", Value, "@odata.type", "")})

 

This will take the source list of attachments (with all its needed info for getting to attachments) and it will add the necessary columns for the Attachments parameter of the SendEmail function.

End result, you will get an email sent with all the attachments that are in the attachments collection.

 

HOWEVER...again, this is a hit from performance as your PowerApp will need to pump down the data in order to attach - still better through Flow.

 

Hope this helps some.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

6 REPLIES 6
Highlighted
Super User
Super User

Re: Email with attachment

@Anonymoushere is the dilema.

When you are dealing with a datacard attachment object, it is missing some of the pieces that it needs to get back to the data.  Keep in mind, when you send email like this, PowerApps has to download the content bytes from the SharePoint and then attach.  

I'll say up-front - if you want to skip the download to send (which could pause your App for a long time depending on the size of the attachments) then look to Flow.  You can easily get content bytes and add multiple attachments through Flow - and it's much faster as you're not limited by the bandwidth of your device you're running PowerApps on. 

 

Now with that said - You can't use the DataCard.Attachments - it is missing key columns needed to get to the data.  You can't use the Form.Updates.Attachments - it is empty (unless you're adding attachments and they've not been submitted).

 

SO - you need to go back to the source.  Let's say your form is getting its Item from a Gallery1.  Typical Item for your form would be Gallery1.Selected.

Ok - so, in this case we CAN go back to the Gallery and we WILL have the information necessary to complete the next step.

AND THAT IS - 

   Office365.SendEmail("abc@def.com","Subject","EmailBody",
{Attachments:AddColumns(Gallery1.Selected.Attachments, "Name", DisplayName, "ContentBytes", Value, "@odata.type", "")})

 

This will take the source list of attachments (with all its needed info for getting to attachments) and it will add the necessary columns for the Attachments parameter of the SendEmail function.

End result, you will get an email sent with all the attachments that are in the attachments collection.

 

HOWEVER...again, this is a hit from performance as your PowerApp will need to pump down the data in order to attach - still better through Flow.

 

Hope this helps some.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Highlighted
Anonymous
Not applicable

Re: Email with attachment

Hi Randy,

 

Thanks for the info. I will do some research doing it via a flow.

Many thanks for putting me in the right direction.

 

Regards,

Adam

Highlighted
Helper V
Helper V

Re: Email with attachment

Hi there,

Could you please explain how you take the attachments from the attachments datacard and put them into a gallery?

Flow scares me, so before I try and learn that (still picking up the PowerApps basics) I’d like to see how the performance is affected in PowerApps.
Highlighted
Super User
Super User

Re: Email with attachment

@d3ell 

Don't let Flow get you scared...it can be a good friend once you get the hang of it.

 

If you are looking to have attachments listed in a Gallery, you just need to set your Items for your Gallery to the (assuming you have another Gallery of the actual records) YourGalleryOfRecords.Selected.Attachments

 

This will give you a Gallery of them as you select on another Gallery.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Highlighted
Anonymous
Not applicable

Re: Email with attachment

Thanks for this explanation. Is it possible to use a similar expression to send only specific items that have been attached to a SharePoint list item (selected from gallery) as an email attachment or would you use Flow for that?

Highlighted
Super User
Super User

Re: Email with attachment

@Anonymous 

I would still consider using Flow for that as it has a bit better ability to get content and in the right format.  But it really depends on what you are designing for.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

Helpful resources

Announcements
Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

August 2020 Community Challenge: Can You Solve These?

August 2020 Community Challenge: Can You Solve These?

We're excited to announce our first cross-community 'Can You Solve These?' challenge!

secondImage

Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

secondImage

Super Users Coming in August

We are excited for the next Super User season.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (7,620)