So I have a simple nightly email that sends a HTML report in the body of an email (works great). I am trying to attach the same data as an Excel attachment but when you open it Windows thinks the file is corrupt. I tried to change file extensions, that didn’t work at all and the process seems so straight forward I am not sure what to look for.
#Run the query data = system.db.runQuery(queryReport, 'xxx') lengthDue = data.getRowCount() if lengthDue > 0: #NEW DATASET Ready for email and Excel conversions rawData = system.dataset.toDataSet(data) #Convert DataSet to Excel and get ready to attach to our email excelstr = system.dataset.dataSetToExcel(1,[rawData]) excelbytes = excelstr.encode("UTF8") filename = "Summary.xls" #Define Email Distribution List recipients = system.db.runScalarQuery("SELECT EmailList FROM ReportDistList WHERE ReportName='Awaiting Inspection Summary'", 'xxx') #Put recipients into a Python list EmailRecipients = [item.strip() for item in recipients.split(',')] myEmail = ['firstname.lastname@example.org'] #Convert DataSet to HTML For Sending In EMAIL EmailHTML = system.dataset.dataSetToHTML(1, rawData, 'Awaiting Inspection Summary') Emailbody = ''' ''' + '<h1>Awaiting Inspection Daily Summary</h1>' + ''' ''' + EmailHTML + '<br/>This is an automated email please do not respond' system.net.sendEmail(smtpProfile='xxxEmail', fromAddremail@example.com', subject='Awaiting Inspection Daily Summary', body=Emailbody, html=True, to=EmailRecipients, bcc=myEmail,attachmentNames=[filename],attachmentData=[excelbytes])
Thanks in advance!