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

Send attachment in Emails using SMTP Connection

Hello, I am trying to send an email with attachments using the 'OnSelect' from a button using the code below using the SMTP connection ...

 

SMTP.SendEmailV2({
From:User().Email,
To:SLoc_Email.Selected.Value,
CC:User().Email,
Subject:"Power Apps 2 - Sloc - " & DropDown_Sloc.Selected.Value,
Body:"<Bold>PowerApps Testing.</Bol> <br><br><br>
This is from " & User().FullName & "<br>
SAP Mvt Type - " & DataCardValue_SAPMvtType.Selected.Value,
IsHtml:true,
Attachments:Table({ FileName: "TheImage.jpg" }, { ContentId: "1" }, { ContentData: Image2.Image }, { ContentType: ""})
});

 

.... Now the code sends the email, that is not a problem but the attachment does not send properly. I get an attached file called 'noname' that does not even have an extension added to the file. If I download the file and add the extension '.png'  to it, it loads and shows me the image.

 

What am I doing wrong?

2 REPLIES 2
Highlighted
Community Support
Community Support

Re: Send attachment in Emails using SMTP Connection

Hi @Anonymous,

 

Properties for attachment are as below according to https://www.carlosag.net/PowerApps/Connectors/SMTP#_Toc69EE4BCA_AttachmentV2:

Name

Type

Summary

ContentData

string(byte)

Content data

Content data

ContentType

string

Content type

Content type

FileName

string

File name

File name

ContentId

string

Content id

Content id

 

It seems that your formula has put the ContentType part to the FileName part. Try:
Attachments:Table({ FileName: "TheImage" }, { ContentId: "1" }, { ContentData: Image2.Image }, { ContentType: ".jpg"})

Regards,

Mona

 

 

Community Support Team _ Mona Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Frequent Visitor

Re: Send attachment in Emails using SMTP Connection

Hello,

 

I ran recently into similar problems with attachments and SMTP. Since I couldnt find a solution online, i will post mine here.

 

The code that @v-monli-msft provided for the Table was almost perfect and the solution to my problem.

Since I got errors when I wrote any kind of ContentType down, I left it blank and added the filetype at the end of the Filename (like @Anonymous  did in the beginning).
There were also some issues with the curley brakets in the table example.

 

Now the table should look like this :

Table(
            {
                FileName: "TheImage.png",
                ContentId: "1",
                ContentData: Media1,
                ContentType: ""
            }
        )

 

If you want to send more than one Attachment, you can expand the table like this :

Table(
            {
                FileName: "TheImage.png",
                ContentId: "1",
                ContentData: Media1,
                ContentType: ""
            },
            {
                FileName: "TheImage2.png",
                ContentId: "2",
                ContentData: Media2,
                ContentType: ""
            },
            ...
        )

 

So the final code to send a SMTP-Email with an attachment can look like this : 

SMTP.SendEmailV3(
    {
        To: employee.Email,
        Body: "Body<p></p>01",
        Subject: "Subject01",
        Attachments: Table(
            {
                FileName: "TheImage1.png",
                ContentId: "1",
                ContentData: Media1,
                ContentType: ""
            }
        )
    }
)

 

And the Result was perfect :

Unbenannt.PNG

 

 

 

 

 

 

 

 

Regards,

Christian

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Find your favorite faces from the community presenting at the Power Platform Community Conference!

Watch Now

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

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.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (8,778)