Sending CSV attachment with action mailer & AWS Sqs queue
<p>I am trying to send an email with a CSV attachment from a Rails AWS EB application (worker tier). </p>

<p>This example will send the email correctly with the data attached, I have hardcoded the CSV string here;</p>

<pre><code>def send_mail
    content = "Example,CSV,Content\n,..."
    attachments['test.csv'] = { mine_type: 'text/csv', content: content}
    mail(   :from =&gt; 'test@mail.com&gt;', 
            :to =&gt; 'person@mail.com', 
            :subject =&gt; 'Email with attachment', 
            :body =&gt; "testing sending email attachment"
        )
end
</code></pre>

<p>However when I send the CSV string from the API I seem to have an encoding problem. The object I am sending is this;</p>

<pre><code>email = {
    from: "test@mail.com",
    to: "person@mail.com",
    subject: "Email with attachment",
    content_type: 'text/html',
    attachments: {
        filename: 'test.csv',
        content: File.read("#{Rails.root}/test.csv")
    }
}
</code></pre>

<p>And the method;</p>

<pre><code>def send_mail(params)
    filename = params[:attachments][:filename]
    attachments[filename] = {   mine_type: 'text/csv', 
                                content_type: 'text/comma-separated-values', 
                                transfer_encoding: '7bit',
                                content: [:attachments][:content]
                            }
    mail(params)
end
</code></pre>

<p>I think there may be a problem with the <strong>transfer_encoding</strong>, If I do not set it to '7bit' the content is base64 encrypted. I have used the action mailer method <strong>attachments.instance_values</strong> to check the content_encoding of the email that works and its binary, however it I set it as binary in the failing example it reverts to base64. If I set the params[:attachments][:content] as a variable then when I log the attachments.instance_values the value is 'binary' but when the mail is received the message is;</p>

<pre><code> ----==_mimepart_57ac6ae25a220_68972ad836f669fc984a7 
    Content-Type: text/comma-separated-values; charset=UTF-8 
    Content-Transfer-Encoding: base64 
    Content-Disposition: attachment; 
    filename=test.csv 
    mine-type: text/csv 
    Content-ID: &lt;57ac6ae259b90_68972ad836f669fc983b0&gt;
</code></pre>

<p>any help or suggestions appreciated. </p>