emailoutlookpowerappsemail-attachmentspowerapps-canvas

Send email with attachment


I am making a power app to send email with multiple attachments.

It sends email with 1 attachment control.

Office365Outlook.SendEmailV2(
"alan@c.com.hk",
"Subject",
"Body",
{
    Attachments: ForAll(
        Attachment_Inspection_Record.Attachments,
        {
            ContentBytes: Value,
            Name: Name
        }
    )
})

I have 5 attachment controls.

There is an error if send email with 5 attachment control attachment:

Office365Outlook.SendEmailV2(
"alan@c.com.hk",
"Subject",
"Body",
{
    Attachments: ForAll(
        Attachment_Inspection_Record.Attachments,
        {
            ContentBytes: Value,
            Name: Name
        },
        Attachment_CCM.Attachments,
        {
            ContentBytes: Value,
            Name: Name
        },
         Attachment_Sitephoto_1.Attachments,
        {
            ContentBytes: Value,
            Name: Name
        }
        Attachment_Sitephoto_2.Attachments,
        {
            ContentBytes: Value,
            Name: Name
        }
        Attachment_Sitephoto_3.Attachments,
        {
            ContentBytes: Value,
            Name: Name
        }
    )

    
});

Solution

  • The ForAll function can be used to transform a table into another - but what you are trying to do is to combine (union) multiple tables, which is not what it does. You can use the Table function to do that - either combining all the attachment controls at first, then using ForAll to extract the name/content, or combining the extracted values that you have working for one control.

    For example, the first option would be similar to the expression below:

    Office365Outlook.SendEmailV2(
        "alan@c.com.hk",
        "Subject",
        "Body",
        {
            Attachments: ForAll(
                Table(
                    Attachment_Inspection_Record.Attachments,
                    Attachment_CCM.Attachments,
                    Attachment_Sitephoto_1.Attachments,
                    Attachment_Sitephoto_2.Attachments,
                    Attachment_Sitephoto_3.Attachments
                ),
                {
                    ContentBytes: Value,
                    Name: Name
                }
            )
        }
    );
    

    While the second would be similar to this:

    Office365Outlook.SendEmailV2(
        "alan@c.com.hk",
        "Subject",
        "Body",
        {
            Attachments: Table(
                ForAll(
                    Attachment_Inspection_Record.Attachments,
                    {
                        ContentBytes: Value,
                        Name: Name
                    }
                ),
                ForAll(
                    Attachment_CCM.Attachments,
                    {
                        ContentBytes: Value,
                        Name: Name
                    }
                ),
                ForAll(
                    Attachment_Sitephoto_1.Attachments,
                    {
                        ContentBytes: Value,
                        Name: Name
                    }
                ),
                ForAll(
                    Attachment_Sitephoto_2.Attachments,
                    {
                        ContentBytes: Value,
                        Name: Name
                    }
                ),
                ForAll(
                    Attachment_Sitephoto_3.Attachments,
                    {
                        ContentBytes: Value,
                        Name: Name
                    }
                )
            )
        }
    );
    

    Both should work fine.