# Email scripting

**URL:** <https://forum.inductiveautomation.com/t/email-scripting/44883>\
**Category:** Ignition\
**Tags:** scripting, ignition80\
**Created:** [March 25, 2021, 12:32am UTC](https://forum.inductiveautomation.com/t/email-scripting/44883 "2021-03-25T00:32:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![panozzosebastian02](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@panozzosebastian02](https://forum.inductiveautomation.com/u/panozzosebastian02)\
**Post date:** [March 25, 2021, 12:32am UTC](https://forum.inductiveautomation.com/t/email-scripting/44883/1 "2021-03-25T00:32:29Z")

</div>

Hello, I am having a problem with system.net.sendEmail. I am using the exact script for sending attachments showed in: [https://docs.inductiveautomation.com/display/DOC80/system.net.sendEmail](https://docs.inductiveautomation.com/display/DOC80/system.net.sendEmail). But i keep on getting an error (java.lang.ClassCastException: java.lang.ClassCastException: Cannot coerce value '[u'TI00365FEN\_1714.pdf']' into type: class java.lang.Boolean). I have sent emails without an attachment using the documentation in the same web page.  
Here is my code (The indentention is correct, but I don't know how to indent it ☹) :

> filePath = system.file.openFile()  
> if filePath != None:  
> fileName = filePath.split("\")[-1]  
> fileData = system.file.readFileAsBytes(filePath)  
> print fileData  
> subject = "Here is the file you requested"  
> body = "Hello, this is an email."  
> recipients = ["[recipient@gmail.com](mailto:recipient@gmail.com)"]  
> system.net.sendEmail(subject, body, 0, recipients, [fileName], [fileData], smptProfile="Mail")``

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 25, 2021, 12:34am UTC](https://forum.inductiveautomation.com/t/email-scripting/44883/2 "2021-03-25T00:34:41Z")

</div>

It would help if you showed your code 🙂

Also, I believe you need to read the files that you want to attach and get the binary data from them which you would include within the `attachmentData` array.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/9/d9fe4df1499797703f29f5ec8e79e271e8351c7c.png)

E.g.

> <https://stackoverflow.com/questions/2497027/read-a-binary-file-python>

---

<div class="post-metadata">

**Author:** ![panozzosebastian02](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@panozzosebastian02](https://forum.inductiveautomation.com/u/panozzosebastian02)\
**Post date:** [March 25, 2021, 6:26pm UTC](https://forum.inductiveautomation.com/t/email-scripting/44883/3 "2021-03-25T18:26:07Z")

</div>

Thanks, but I am reading it as bytes with system.file.readFileAsBytes. And also with the python method, but nothing seems to work.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [March 25, 2021, 6:27pm UTC](https://forum.inductiveautomation.com/t/email-scripting/44883/4 "2021-03-25T18:27:46Z")

</div>

I think your problem is that you’re mixing positional and keyword arguments in your function call.

Try using keyword arguments for every argument, not just `smtpProfile`. (which you have typo’d, btw)

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [March 25, 2021, 6:32pm UTC](https://forum.inductiveautomation.com/t/email-scripting/44883/5 "2021-03-25T18:32:46Z")

</div>

Was just getting ready to post that according to the function signature found [here](https://docs.inductiveautomation.com/display/DOC81/system.net.sendEmail) in the manual, you’re actually supplying the fileData array as the html flag.

@Kevin.Herron beat me to it.

Should also be noted that the SMTP server Addtress and from email Address are not optional parameters and you aren’t supplying those at all.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [March 25, 2021, 7:35pm UTC](https://forum.inductiveautomation.com/t/email-scripting/44883/6 "2021-03-25T19:35:00Z")

</div>

> [@lrose](#):
>
> you’re actually supplying the fileData array as the html flag.

That's exactly what I suspected too, before seeing the code 😄

---

<div class="post-metadata">

**Author:** ![panozzosebastian02](https://avatars.discourse-cdn.com/v4/letter/p/e95f7d/32.png) [@panozzosebastian02](https://forum.inductiveautomation.com/u/panozzosebastian02)\
**Post date:** [March 25, 2021, 8:37pm UTC](https://forum.inductiveautomation.com/t/email-scripting/44883/7 "2021-03-25T20:37:28Z")

</div>

This solved my problem, thank you! But now I shows another error message But it is sending the email anyway.
