# How to attach file in disk to an email dynamically?

**URL:** <https://community.ofelia.com/t/how-to-attach-file-in-disk-to-an-email-dynamically/11098>\
**Category:** Q&A\
**Created:** [15 February 2022 04:54 UTC](https://community.ofelia.com/t/how-to-attach-file-in-disk-to-an-email-dynamically/11098 "2022-02-15T04:54:46Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![SachinM](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@SachinM](https://community.ofelia.com/u/SachinM)\
**Post date:** [15 February 2022 04:54 UTC](https://community.ofelia.com/t/how-to-attach-file-in-disk-to-an-email-dynamically/11098/1 "2022-02-15T04:54:46Z")

</div>

We tried to attach file by running a script as follows. But, it didn't attach file to the email. Let me know if there are any other ways of doing this or mistakes in this attempt.

> import java.io.File;  
> import java.util.logging.Logger;
> 
> File readFile() {  
> &nbsp;&nbsp; &nbsp;Logger logger = Logger.getLogger("org.bonitasoft");  
> &nbsp;&nbsp; &nbsp;File file = new File("C:\\Users\\sachinm\\Downloads\\testDoc.txt")  
> &nbsp;&nbsp; &nbsp;logger.info("File read");  
> &nbsp;&nbsp; &nbsp;return file;  
> }
> 
> readFile();

---

<div class="post-metadata">

**Author:** ![guillaume.leclerre\_3](https://avatars.discourse-cdn.com/v4/letter/g/f4b2a3/32.png) [@guillaume.leclerre\_3](https://community.ofelia.com/u/guillaume.leclerre_3)\
**Post date:** [15 February 2022 07:29 UTC](https://community.ofelia.com/t/how-to-attach-file-in-disk-to-an-email-dynamically/11098/2 "2022-02-15T07:29:12Z")

</div>

Hi Sachin,

To attach a file to your email, you can create a new document in your pool and initiate it from the file&nbsp;system or contract.&nbsp;

So, for your example, you can specify your file "C:\\Users\\sachinm\\Downloads\\testDoc.txt".

In the connector, you just have to select your document as an attachment.

I hope this will help you.
