# system.net.sendEmail with optional attachment

**URL:** <https://forum.inductiveautomation.com/t/system-net-sendemail-with-optional-attachment/111983>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [November 6, 2025, 7:20am UTC](https://forum.inductiveautomation.com/t/system-net-sendemail-with-optional-attachment/111983 "2025-11-06T07:20:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecurreaux](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@ecurreaux](https://forum.inductiveautomation.com/u/ecurreaux)\
**Post date:** [November 6, 2025, 7:20am UTC](https://forum.inductiveautomation.com/t/system-net-sendemail-with-optional-attachment/111983/1 "2025-11-06T07:20:50Z")

</div>

Hello,  
Using the system.net.sendemail function, I would like to make sending attachments in an email optional.

In this case, how do I write the [attachmentNames] and [attachmentData] arguments in the function?

Thank you for your help.

Manu

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [November 6, 2025, 7:31am UTC](https://forum.inductiveautomation.com/t/system-net-sendemail-with-optional-attachment/111983/2 "2025-11-06T07:31:34Z")

</div>

> [@Ignition Edge sends emails but no attachments](https://forum.inductiveautomation.com/t/ignition-edge-sends-emails-but-no-attachments/111666/14):
>
> This works for me, albeit I didn’t test on Edge; filePath = system.file.openFile() if filePath != None: # This gets the filename without the C:\folder stuff fileName = filePath.split("\\")[-1] fileData = system.file.readFileAsBytes(filePath) smtp\_server = "test" sender = "test" subject\_mail = "Here is the file you requested" body\_mail = "Hello, this is an email." recipients = ["test"] system.net.sendEmail( smtpProfile = smtp\_server, fromAddr = sender, sub…

---

<div class="post-metadata">

**Author:** ![ecurreaux](https://avatars.discourse-cdn.com/v4/letter/e/db5fbb/32.png) [@ecurreaux](https://forum.inductiveautomation.com/u/ecurreaux)\
**Post date:** [November 6, 2025, 7:49am UTC](https://forum.inductiveautomation.com/t/system-net-sendemail-with-optional-attachment/111983/3 "2025-11-06T07:49:35Z")

</div>

Thanks for your reply, and without attachments with the same code is it ok?

---

<div class="post-metadata">

**Author:** ![David\_Stone](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/david_stone/32/79749_2.png) [@David\_Stone](https://forum.inductiveautomation.com/u/David_Stone)\
**Post date:** [November 6, 2025, 7:53am UTC](https://forum.inductiveautomation.com/t/system-net-sendemail-with-optional-attachment/111983/4 "2025-11-06T07:53:53Z")

</div>

Yeah just omit the two attachment parameters.

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [November 6, 2025, 7:54am UTC](https://forum.inductiveautomation.com/t/system-net-sendemail-with-optional-attachment/111983/5 "2025-11-06T07:54:42Z")

</div>

If you have no attachments you can use simpler code;

```python
# This code would send a simple plain-text email to a single recipient, with no attachments
body = "Hello, this is an email."
recipients = ["bobsmith@mycompany.com"]
system.net.sendEmail("mail.mycompany.com",
 "myemail@mycompany.com", "Here is the email!", body, 0, recipients)

```

---

<div class="post-metadata">

**Author:** ![Matrix\_Engineering](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/matrix_engineering/32/19781_2.png) [@Matrix\_Engineering](https://forum.inductiveautomation.com/u/Matrix_Engineering)\
**Post date:** [November 6, 2025, 7:56am UTC](https://forum.inductiveautomation.com/t/system-net-sendemail-with-optional-attachment/111983/6 "2025-11-06T07:56:20Z")

</div>

That code only executes if there is a valid filepath, so there has to be an attachment.
