Email scripting

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. 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 :frowning:) :

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"]
system.net.sendEmail(subject, body, 0, recipients, [fileName], [fileData], smptProfile="Mail")``

It would help if you showed your code :slight_smile:

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.

E.g.

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

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)

Was just getting ready to post that according to the function signature found here 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.

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

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