Mail attachments (.pdf) are being saved to desktop

Hi Everyone,

In my application, I am sending mails with binary attachments (in pdf format) and I am getting byte array by running jasper reports, used that byte array to create a binary attachment. When email sent surprisingly, I can see the same email attachment (.pdf) on my desktop. Strange.

Please check the below code :

var bytes = null;	
// Get the bytes by running the jasper report.
bytes = plugins.jasperPluginRMI.runReport(globals.SERVER_NAME , reportName, pdfName , plugins.jasperPluginRMI.OUTPUT_FORMAT.PDF , params);
var attachment = plugins.mail.createBinaryAttachment(reportName , bytes);
plugins.mail.sendMail(to , from , csubject , cbody , null , null , [attachment] , properties);

Can please someone share to me, what went wrong and how can I resolve it.

Servoy : 7.4.1
Java : 7
OS : Windows

Thanks In Advance

What is the value of variable ‘pdfName’ ? If it contains a filename to your desktop directory, then that is your answer.

Hi Boonstra,

I am hard codding some name in that “pdfName” variable, something like, “Balance.pdf”. I am wondering, how that locating to Desktop. Can you throw some light on this issue.

Thanks

If you only supply a filename then it will be created in the current working directory of your application. In your case I suppose it’s the desktop directory.

Hi Boonstra,

Thanks alot for the information. I don’t want the email’s attachments saving on the “Desktop”, can you please share to me , how can I achieve this. May I need to pass some temporary file name to , “plugins.jasperPluginRMI.runReport(globals.SERVER_NAME , reportName, pdfName , plugins.jasperPluginRMI.OUTPUT_FORMAT.PDF , params);” instead of some hard codded name. Please suggest me, how to achieve this.

Thanks

If you don’t want an actual file being created just supply null as filename.

bytes = plugins.jasperPluginRMI.runReport(globals.SERVER_NAME , reportName, null , plugins.jasperPluginRMI.OUTPUT_FORMAT.PDF , params);

Hi Boonstra,

Its working fine , thanks for your help

Thanks