cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
AdamDahama
Level: Powered On

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
Super User
Super User

Re: Email with attachment

@AdamDahamahere 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.
6 REPLIES 6
Super User
Super User

Re: Email with attachment

@AdamDahamahere 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.
AdamDahama
Level: Powered On

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

d3ell
Level: Powered On

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.
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.
asdf2
Level: Powered On

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?

Super User
Super User

Re: Email with attachment

@asdf2 

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
firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

FirstImage

Power Platform World Tour

Coming to a city near you

thirdimage

PowerApps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

FourthImage

Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

SecondImage

Power Platform Summit North America

Register by September 5 to save $200

Top Kudoed Authors
Users Online
Currently online: 189 members 5,516 guests
Please welcome our newest community members: