the-refinery/sparkpost_rails

Attaching files

Opened this issue · 0 comments

8vius commented

I don't quite get how to attach files to an email, I checked the API and it says it should be under the content.attachments section as an array, yet doing this doesn't seem to work, this is how I'm sending my email:

  def buyer_tickets_email(order)
    @order = order
    data = {
      substitution_data: purchase_order_details(@order),
      content: {
        attachments: order.tickets.map do |ticket|
          {
            name: "#{ticket_file_name(ticket)}.pdf",
            type: "application/pdf",
            data: ticket.to_pdf
          }
        end
      },
      template_id: 'buyer-tickets-email'
    }
    mail to: @order.email, subject: I18n.t('tickets_mailer.subject'), sparkpost_data: data
  end

Am I missing something? The email arrives correctly yet without the attached pdfs