the-refinery / sparkpost_rails

Sparkpost delivery method for ActionMailer
MIT License
66 stars 61 forks source link

Attaching files #63

Open 8vius opened 5 years ago

8vius commented 5 years ago

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