# Export dataset to CSV and send as email attachment

**URL:** <https://forum.inductiveautomation.com/t/export-dataset-to-csv-and-send-as-email-attachment/36529>\
**Category:** Ignition\
**Created:** [July 9, 2020, 9:39am UTC](https://forum.inductiveautomation.com/t/export-dataset-to-csv-and-send-as-email-attachment/36529 "2020-07-09T09:39:30Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![jmacascas](https://avatars.discourse-cdn.com/v4/letter/j/aeb1de/32.png) [@jmacascas](https://forum.inductiveautomation.com/u/jmacascas)\
**Post date:** [July 10, 2020, 12:56am UTC](https://forum.inductiveautomation.com/t/export-dataset-to-csv-and-send-as-email-attachment/36529/8 "2020-07-10T00:56:09Z")

</div>

Hi Guys, here’s my script.

```auto
from datetime import datetime 

myDataset=system.tag.read("[default]Machine/machine1/Stats/Monitoring/TimeRecord").value
hostName = system.tag.read("[default]Machine/machine1/Hostname").value

#Iterate the dataset
for row in range(myDataset.getRowCount()):
	for col in range(myDataset.getColumnCount()):
		myDataset.getValueAt(row, col) 

excelstr = system.dataset.dataSetToExcel(1,[myDataset])
excelbytes = excelstr.encode("UTF8")
filename = hostName +"_"+(datetime.today().strftime("%m-%d-%y - %H %M %S"))+ ".xls"

body = "<HTML><BODY><H1>Test101</H1>"
#body += "This is a system generate email <font color='black'>black</font></BODY></HTML>"
recipients = ["jmacascas@email.com"]
cc_recipients = [""]
smtp_server = "default"
subject = "Here is the file you requested"
system.net.sendEmail(smtpProfile=smtp_server, fromAddr="ignition@email.com", subject= subject, body=body, html=0, to=recipients, cc=cc_recipients,[filename],[excelbytes])

```

but i’m getting this syntax error.  
SyntaxError: (‘non-keyword arg after keyword arg’, (’’, 26, 146, ‘system.net.sendEmail(smtpProfile=smtp\_server, [fromAddr="ignition@email.com](mailto:fromAddr=%22ignition@email.com)", subject= subject, body=body, html=0, to=recipients, cc=cc\_recipients,[filename],[excelbytes])\n’))

---

_[View the full topic](https://forum.inductiveautomation.com/t/export-dataset-to-csv-and-send-as-email-attachment/36529)._
