# Attach CSV String as attachment

**URL:** <https://www.ruby-forum.com/t/attach-csv-string-as-attachment/165177>\
**Category:** Rails\
**Created:** [April 9, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/attach-csv-string-as-attachment/165177 "2009-04-09T21:30:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgiorno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e274bd/32.png) [@mgiorno](https://www.ruby-forum.com/u/mgiorno)\
**Post date:** [April 9, 2009, 9:30pm UTC](https://www.ruby-forum.com/t/attach-csv-string-as-attachment/165177/1 "2009-04-09T21:30:25Z")

</div>

I am trying to take a csv string output and send it as a file  
attachment, but keep my data is only coming out as gobbly gook. The csv  
string is valid going into the mailer action.

Valid CSV

id,name,dealer\_code,created\_at,quantity,total\_quote,shipping\_cost  
1000012,Testing project,Thu Apr 09 16:31:08 UTC 2009,0,0,0.0  
1000013,test,Thu Apr 09 16:35:19 UTC 2009,0,0,0.0

In Action Mailer, I have:

def report(csv, name)  
.  
.  
.  
body :name =\> name  
attachment “text/csv; charset=utf-8” do |a|  
a.body = csv  
a.filename = name  
end  
end

unfortunately, this gives me:

–mimepart\_49de4abf9b848\_6d414263a4194  
Content-Type: text/csv; name=“New projects”  
Content-Transfer-Encoding: Base64  
Content-Disposition: attachment; filename=“New projects”

aWQsbmFtZSxkZWFsZXJfY29kZSxjcmVhdGVkX2F0LHF1YW50aXR5LHRvdGFs  
X3F1b3RlLHNoaXBwaW5nX2Nvc3QKMTAwMDAxMixUZXN0aW5nIHByb2plY3Qs  
LFRodSBBcHIgMDkgMTY6MzE6MDggVVRDIDIwMDksMCwwLDAuMAoxMDAwMDEz  
LHRlc3QsLFRodSBBcHIgMDkgMTY6MzU6MTkgVVRDIDIwMDksMCwwLDAuMAo=
