It took me a while to get this one to work, many forum searches later. To save someones pain, here is how to export table data as XLS and email it in perspective. If you unhash the download line and hash everything below you can download the file instead.
table = self.parent.parent.getChild("Table Container").getChild("Table").props.data #Table you want to send/save
excelstr = system.dataset.dataSetToExcel(True,[table])
excelbytes = excelstr.encode("UTF8")
fileName = 'test.xls'
#system.perspective.download(fileName, excelbytes)
smtp_server = 'Gmail' #Name of of the SMTP server in the gateway
sender = "myemail@email.com"
subject = "Here is the file you requested"
body = "Hello, this is an email"
recipients = ["myemail@email.com"]
system.net.sendEmail(smtpProfile=smtp_server, fromAddr=sender, subject=subject, body=body, html=1, to=recipients, attachmentNames=[fileName], attachmentData=[excelbytes])