# How to attach a file to email

**URL:** <https://community.ofelia.com/t/how-to-attach-a-file-to-email/7312>\
**Category:** Q&A\
**Created:** [8 May 2016 14:02 UTC](https://community.ofelia.com/t/how-to-attach-a-file-to-email/7312 "2016-05-08T14:02:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kari.paukku](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@kari.paukku](https://community.ofelia.com/u/kari.paukku)\
**Post date:** [8 May 2016 14:02 UTC](https://community.ofelia.com/t/how-to-attach-a-file-to-email/7312/1 "2016-05-08T14:02:06Z")

</div>

Hi,

I can send an email from Bonita ok but haven’t managed to figure out how to add an attachment to the email message?

The documentation says “Include email attachments defined as a variables or expressions” but doesn’t have any examples. I’m assuming that a Groovy script is needed but can’t find anything that I could have applied.

Where could I find an example where the attachment can added to the email, preferable using a variable so that the name doesn’t need be hardcoded.

Thanks,  
ktp

Bonita 7.2.3 CE

ps. I have the file written to the disk prior sending the email, so the file already exists at the point of creating the email.

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [8 May 2016 18:29 UTC](https://community.ofelia.com/t/how-to-attach-a-file-to-email/7312/2 "2016-05-08T18:29:21Z")

</div>

When it says variable it means document variable as defined in the Pool Documents.

So for example you have a document defined as _fred_ and you want to attach it to an email, in the connector get to that point, add a row and then add the document _fred_ to it.

That’s it, no need for groovy script.

regards  
Seán

_PS: If this reply answers your question, please mark a resolved_

---

<div class="post-metadata">

**Author:** ![kari.paukku](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@kari.paukku](https://community.ofelia.com/u/kari.paukku)\
**Post date:** [8 May 2016 19:00 UTC](https://community.ofelia.com/t/how-to-attach-a-file-to-email/7312/3 "2016-05-08T19:00:55Z")

</div>

Sean,  
thanks - I did find the document section for the lane and created a document called “fred” to which I assigned a file. How could I assign the file name dynamically (the idea is that earlier in the process the file gets created and has a named decided at that point (so every time a unique name). This file should then be assign to document variable (“fred” in this case).

thanks,  
ktp

---

<div class="post-metadata">

**Author:** ![kari.paukku](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@kari.paukku](https://community.ofelia.com/u/kari.paukku)\
**Post date:** [8 May 2016 19:28 UTC](https://community.ofelia.com/t/how-to-attach-a-file-to-email/7312/4 "2016-05-08T19:28:00Z")

</div>

Tested it a little bit more and sending an email with attachment using the document (and selecting the file at the point when creating the document in Bonita, worked fine.

So far no luck trying to have the file name assigned dynamically If I find something I’ll update it here.

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [9 May 2016 03:22 UTC](https://community.ofelia.com/t/how-to-attach-a-file-to-email/7312/5 "2016-05-09T03:22:57Z")

</div>

There is no way to interact with the connector dynamically, it is fixed and solid in it’s implementation.

I find the inbuilt email connector useful for quick emails only.

To do dynamic work

1. you can assign document variable _fred_ to the email, then you can then assign one of bill.docx, george.xlx, peter.ppt to fred and send that. But you are fixed to only one document…

2. you write your own email connector based on the implemented connector that will accept a list of strings (document variables) which you can then attach to the email.

3. write your own script code similar to these:

[http://stackoverflow.com/questions/6806407/add-attachment-as-stream-in-commons-email](http://stackoverflow.com/questions/6806407/add-attachment-as-stream-in-commons-email)  
[https://vangjee.wordpress.com/2010/11/02/how-to-create-an-in-memory-pdf-report-and-send-as-an-email-attachment-using-itext-and-java/](https://vangjee.wordpress.com/2010/11/02/how-to-create-an-in-memory-pdf-report-and-send-as-an-email-attachment-using-itext-and-java/)

regards  
Seán

---

<div class="post-metadata">

**Author:** ![kari.paukku](https://avatars.discourse-cdn.com/v4/letter/k/77aa72/32.png) [@kari.paukku](https://community.ofelia.com/u/kari.paukku)\
**Post date:** [10 May 2016 02:45 UTC](https://community.ofelia.com/t/how-to-attach-a-file-to-email/7312/6 "2016-05-10T02:45:25Z")

</div>

Sean,

the first (“1) you can assign document variable fred … assign one of bill.docx, george.xlx, peter.”) option would be sufficient for me - will start to have a look how that can be done.  
More later as I find out how that’s done.

ktp
