Skip to content

Attachment shows as text in body of email #25

Open
@jbsmithj1981

Description

@jbsmithj1981

This is the email body:

Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;
 charset=UTF-8
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="Daily Status 2014-09-02.xlsx"
Content-ID: <[email protected]>

UEsDBBQAAAgIAACYn+tjOGvU2QAAAEECAAALAAAAX3JlbHMvLnJlbHOtksFO
wzAMhu88ReT7mm5ICKFluyCk3RAqD2ASt43axJEToLw9gQNiaAgOO1r2//3f
wdv9Emb1QpI9RwPrpgVF0bLzcTDw2N2trmG/2z7QjKVe5NGnrGokZgNjKelG
62xHCpgbThTrpmcJWOoog05oJxxIb9r2Sst3BhwzVYcyUDGwzPqVZXpinpoK
A9W9JfpPFfe9t3TL9jlQLCcaf1yAOjgDcnBr0L+4OLb3wjVpWejcNoEKOiz4
CV+l2kNSPOUvr83fXpjSubVoKRQduVNGlx9G+ugVdhfvUEsDBBQAAAgIAACY
n+vvyqPEyAEAAAkFAAANAAAAeGwvc3R5bGVzLnhtbKVU22rcMBB971cIfUBl....

This is my mailer:

class StatusMailer < ActionMailer::Base
    default to: Proc.new { ['[email protected]']}, from: "[email protected]"

    def daily_coding_status

        # execute sp
        status_results = DailyStatus.execute_procedure("get_coding_status")

        # cache date
        @date = Time.zone.today.to_s

        xlsx = render_to_string handlers: [:axlsx], formats: [:xlsx], template: "status_mailer/status", locals: { status_results: status_results }
        attachments["Daily Status #{@date}" + ".xlsx"] = { mime_type: Mime::XLSX, content: xlsx}
        mail(:subject => "#{@date}  Status Report")
    end
end

This is the template 'status.xlsx.axlsx':

# build excel file
wbook = xlsx_package.workbook
wbook.add_worksheet(:name => "Daily Status") do |sheet|
    sheet.add_row ["Parent Location RID", "Location RID", "Location Name", "Unique Tools", "Total Parts", "Total Coded", "Total Not Coded", "Total Questions", "Total Do Not Code",
          "Total Ready To Code", "Unique Parts", "Unique Coded", "Unique Not Coded", "Unique Questions", "Unique Do Not Code", "Unique Ready To Code", "Percent Coded",
          "1 Day Difference", "7 Day Difference", "30 Day Difference"]

    status_results.each do |result|

    data_row = [result['parent_location_rid'], result['location_rid'], result['location_name'], result['unique_tools'], result['total_parts'], result['total_coded'], result['total_not_coded'],
                result['total_questions'], result['total_do_not_code'], result['total_ready_to_code'], result['unique_parts'], result['unique_coded'], result['unique_not_coded'], result['unique_questions'],
                result['unique_do_not_code'], result['unique_ready_to_code'], result['percent_coded'], result['one_day_difference'], result['seven_day_difference'], result['thirty_day_difference']]

      #add the row to the sheet
      sheet.add_row data_row, :types => [:string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string, :string]
    end
end

I can't see what I'm doing incorrectly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions