Home Email attached csv in grails mail?
Reply: 0

Email attached csv in grails mail?

Karthigeyan R
1#
Karthigeyan R Published in 2018-02-07 09:22:20Z

Currently I am using the export plugin to create an csvfile on the fly on the server and then sending it to the browser via response.outputstream (done by the export plugin). Instead, what I want it to create the csv file and once done, email it to the user.looked into the export plugin code and it looks like it writes to the response output stream. How to read from this output stream, create a file, not store it to disc and just email it instead?

 def csv=responseArchive
            def csvDate=csv?.date
            def csvArchive=csv?.archive
            def csvReport=csv?.reporting
            def csvDelta=csv?.totals
            response.contentType = grailsApplication.config.grails.mime.types['csv']
            response.setHeader("Content-disposition", "attachment; filename=test.csv")
            List fields = ["date", "archive", "reporting", "totals"]
            Map labels = ["csvDate": "Date","csvArchive":"Archive","csvReport":"Reporting","csvDelta":"Totals"]
            // Formatter closure
            def upperCase = { domain, value ->
                return value.toUpperCase()
            }
            def title = { domain, value ->
                return domain?.date + ": "+domain?.archive+ ": " + domain?.reporting+ ": " + domain?.delta
            }
            String Csv="csv"
            Map formatters = [csv: upperCase]
            Map parameters = [title: "Report", "column.widths": [0.2, 0.3, 0.5]]
            exportService.export(Csv,response.outputStream, responseArchive, fields, labels, formatters, parameters)
    sendMail {
             multipart true
             to "test@gmail.com"
             body "Hello Watcher!"
             attachBytes "Some-File-Name.csv", "text/csv", contentOrder.getBytes("UTF-8")}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.296135 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO