[IGN-14996]8.3 net.sendEmail attachments not functioning as expected

This code worked fine in 8.1, but now I get PDFs I can’t open. Or JPEGs or PNGs.

In the code below, I am creating a PDF byte array from system.report.executeReport(). For troubleshooting, I am also saving the file as a PDF.

reportResult = system.report.executeReport(
                              path=reportName, 
                              project = projectName, 
                              parameters = params, 
                              fileType = "pdf")
    
system.file.writeFile(r"E:\Downloads\Projects\ReportTest\testfile.pdf", reportResult)

system.net.sendEmail(
            fromAddr = "Press10Site@customer.com",
            subject = "Press 10 Site Alarm Frequency Report",
            to = toList,
            html = False,
            body = "File type = {0}".format(type(reportResult)),
            attachmentNames = ["MyFile.pdf"],
            attachmentData = [reportResult],
            smtpProfile = "customerSMTP"
            )

When I get the email, the “pdf” file attached gives me this:

image

Meanwhile, the file that was saved gives me a good pdf file. Likewise, using the Report’s integral email scheduler, I get the same good PDF file.

Because I can save the file and open as PDF, I know it isn’t the report.executeReport() that is going wrong.

Because I can email the file from other IGN utilities (Report’s Integral Scheduler), I don’t think my company’s email, or the customer’s company’s email are doing bad things to attachments.

That would seem to leave system.net.sendEmail() as the prime suspect, I’m afraid. I reiterate: this is code I have been using in 8.1 that has worked well and this is my first time working on 8.3, though I did not see any real changes to net.sendEmail from 8.1 to 8.3 in the docs.

Caveat: I am a good try-er, but this GW is owned by the customer and they have their own dedicated and competent team of IGN managers, and therefore they have the final say over any testing that would require admin access.

Anyone else experience this? Any ideas?

I bet this is just a bug we introduced during the overhaul of how RPC works...

if you called system.net.sendEmail with the same attachment data but from gateway scope, e.g. from a tag event script or gateway timer script or something, I suspect it would work.

1 Like

Even if I'm right, you should call support and let them take a look. If it's broken they'll reproduce and confirm before making a ticket. I can't create a bug ticket based on my 30 second dive and a WAG about what might be wrong.

Easy enough to test! More info in a moment…

That worked. Thank you!

Well, it's a workaround, and perhaps confirmation of my hunch, but not a real solution.

Luckily for me, I intended it for Gateway scope and using the script console to trigger the function was only for testing.

If it would still be helpful, I can still contact support and have them confirm whatever you’d need.

Well for posterity, my hunch is that the attachment data is gzipped and then base64 encoded on the client side but only base64 decoded once it reaches the gateway - the unzipping got lost somewhere in the RPC overhaul.

@paul-griffith

1 Like

Yeah, sure looks that way. The respective encoding/decoding steps didn't change as part of RPC, but it looks like the way the code paths got collapsed ended up causing this. I'll get a ticket going internally.

1 Like