# Sending an e-mail with an attachment to a recipient using the file upload component and a send button

**URL:** <https://forum.inductiveautomation.com/t/sending-an-e-mail-with-an-attachment-to-a-recipient-using-the-file-upload-component-and-a-send-button/50941>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 14, 2021, 7:21am UTC](https://forum.inductiveautomation.com/t/sending-an-e-mail-with-an-attachment-to-a-recipient-using-the-file-upload-component-and-a-send-button/50941 "2021-09-14T07:21:42Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![johannes.B](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@johannes.B](https://forum.inductiveautomation.com/u/johannes.B)\
**Post date:** [September 14, 2021, 7:21am UTC](https://forum.inductiveautomation.com/t/sending-an-e-mail-with-an-attachment-to-a-recipient-using-the-file-upload-component-and-a-send-button/50941/1 "2021-09-14T07:21:42Z")

</div>

Hello,  
I am currently having problems sending an e-mail via a button that attaches the document which was uploaded in the file upload component. Something like this:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/7/17b22f7c546e0f18127c56b435276ae4ff65063f.png)  
If i directly use a onfileRevieve script on the file upload component everything works.  
But i don’t know how to access the uploaded data in the fileUploadComponent through the button.

I had something in mind like following script for the button:  
filePath = self.getSibling(“FileUpload”).event.file.name  
if filePath != None:  
fileName = self.getSibling(“FileUpload”).event.file.name  
fileData = self.getSibling(“FileUpload”).event.file.getBytes()  
smtp = “_**"  
sender = "**__"  
subject = “New ignition feedback”  
body = self.getSibling(“TextArea”).props.text  
recipients = ["\*\*\*\*\*\*\*\*@_\*\*\*\*\*\*”]  
system.net.sendEmail(smtp, sender, subject, body, 0, recipients, [fileName], [fileData])  
I know that this doesn’t work but i hope it makes it a bit clearer to understand.

Best regards  
Johannes

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [September 14, 2021, 12:21pm UTC](https://forum.inductiveautomation.com/t/sending-an-e-mail-with-an-attachment-to-a-recipient-using-the-file-upload-component-and-a-send-button/50941/2 "2021-09-14T12:21:09Z")

</div>

You’ll have to save the uploaded file in a temporary location, then retrieve it in the send button’s script. And have a mechanism to clean up the temporary location of abandoned uploads (never sent).

---

<div class="post-metadata">

**Author:** ![johannes.B](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@johannes.B](https://forum.inductiveautomation.com/u/johannes.B)\
**Post date:** [October 21, 2021, 12:07pm UTC](https://forum.inductiveautomation.com/t/sending-an-e-mail-with-an-attachment-to-a-recipient-using-the-file-upload-component-and-a-send-button/50941/3 "2021-10-21T12:07:07Z")

</div>

Thanks a lot. That worked…

---

<div class="post-metadata">

**Author:** ![Varsha\_Gottipati1](https://avatars.discourse-cdn.com/v4/letter/v/ce73a5/32.png) [@Varsha\_Gottipati1](https://forum.inductiveautomation.com/u/Varsha_Gottipati1)\
**Post date:** [June 27, 2024, 10:25pm UTC](https://forum.inductiveautomation.com/t/sending-an-e-mail-with-an-attachment-to-a-recipient-using-the-file-upload-component-and-a-send-button/50941/4 "2024-06-27T22:25:00Z")

</div>

Hello, Could you please elaborate on this? I am new to scripting and am having a hard time to build this. When you say, save to a temporary location, is it the gateway that you are referring to? and what script do we use to retrieve and clean up? In my application, I have two buttons, one that allows me to attach file using "path = system.file.openFile()". I am not sure if I am approaching the issue in a right way. Kindly advice. Thank you.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 28, 2024, 12:00am UTC](https://forum.inductiveautomation.com/t/sending-an-e-mail-with-an-attachment-to-a-recipient-using-the-file-upload-component-and-a-send-button/50941/5 "2024-06-28T00:00:51Z")

</div>

> [@Varsha\_Gottipati1](#):
>
> gateway that you are referring to?

Yes, all Perspective scripts run in the gateway, so the gateway is your only choice.

The simplest method is to use a gateway folder to hold these files, and remove them after the email is sent. Use a separate timer event to occasionally scan the folder for old files (by timestamp, perhaps) and delete them.

---

<div class="post-metadata">

**Author:** ![Sayantan\_Chatterjee](https://avatars.discourse-cdn.com/v4/letter/s/9de053/32.png) [@Sayantan\_Chatterjee](https://forum.inductiveautomation.com/u/Sayantan_Chatterjee)\
**Post date:** [September 23, 2024, 1:40pm UTC](https://forum.inductiveautomation.com/t/sending-an-e-mail-with-an-attachment-to-a-recipient-using-the-file-upload-component-and-a-send-button/50941/6 "2024-09-23T13:40:09Z")

</div>

How can we remove the temp file?  
I checked the temp file with system.file.fileexists but its returned as false!
