# Email Attachments

**URL:** <https://forum.servoy.com/t/email-attachments/21217>\
**Category:** Questions\
**Created:** [April 16, 2024, 12:41pm UTC](https://forum.servoy.com/t/email-attachments/21217 "2024-04-16T12:41:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alasdairs](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@alasdairs](https://forum.servoy.com/u/alasdairs)\
**Post date:** [April 16, 2024, 12:41pm UTC](https://forum.servoy.com/t/email-attachments/21217/1 "2024-04-16T12:41:52Z")

</div>

Hi all,

I have just finished setting up emails, but am wondering how I could attach a pdf to the email. I tried using plugins.mail.createTextAttachment(filename, textdata) but it doesn’t seem to work. Are you meant to just put the filepath of the file you want to send in the filename? I’m not sure what to put in the textdata field.

Thanks,  
Alasdair

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [April 16, 2024, 1:54pm UTC](https://forum.servoy.com/t/email-attachments/21217/2 "2024-04-16T13:54:00Z")

</div>

Try

```auto
var attachment_array = plugins.mail.createBinaryAttachment(attachment_name, attachment);
						success = plugins.mail.sendMail(send_to,
							from_email,
							send_subject,
							sendHTML,
							send_cc,
							send_bcc,
							[attachment_array]);

```

---

<div class="post-metadata">

**Author:** ![alasdairs](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@alasdairs](https://forum.servoy.com/u/alasdairs)\
**Post date:** [April 17, 2024, 12:56pm UTC](https://forum.servoy.com/t/email-attachments/21217/3 "2024-04-17T12:56:01Z")

</div>

Hi Rafig,

Thanks, that seems to be mostly working but every time I try to open the attachment I have sent it’s a broken file.

Here’s my code:

```auto
plugins.mail.createTextAttachment(foundset.order_uuid + '.pdf', scopes.global.pdfPath('Customer_Orders') + foundset.order_uuid + '.pdf')

```

The error message I get is:

The file “file.pdf” could not be opened.  
It may be damaged or use a file format that Preview doesn’t recognise.

Thanks,  
Alasdair

---

<div class="post-metadata">

**Author:** ![mboegem](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/mboegem/32/4399_2.png) [@mboegem](https://forum.servoy.com/u/mboegem)\
**Post date:** [April 17, 2024, 1:16pm UTC](https://forum.servoy.com/t/email-attachments/21217/4 "2024-04-17T13:16:07Z")

</div>

Hi Alasdair,

you need to use ‘createBinaryAttachment’ instead of the text variant

---

<div class="post-metadata">

**Author:** ![rafig](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/rafig/32/4463_2.png) [@rafig](https://forum.servoy.com/u/rafig)\
**Post date:** [April 17, 2024, 2:18pm UTC](https://forum.servoy.com/t/email-attachments/21217/5 "2024-04-17T14:18:26Z")

</div>

Alasdair,  
as Marc said (& as I put in my code above), use createBinaryAttachment…

---

<div class="post-metadata">

**Author:** ![alasdairs](https://avatars.discourse-cdn.com/v4/letter/a/839c29/32.png) [@alasdairs](https://forum.servoy.com/u/alasdairs)\
**Post date:** [April 17, 2024, 2:27pm UTC](https://forum.servoy.com/t/email-attachments/21217/6 "2024-04-17T14:27:36Z")

</div>

Yeah sorry, didn’t read it correctly. It’s working now.
