1

I am experiencing problems with ActionMailer, AWS SES and attachments (not inline) in Rails 3.2.13. When viewing the email in Gmail, it's displayed without any problems. When viewing it in Apple Mail or Sparrow, either attachment is missing and the body is displayed or vice-versa.

The headers for the email are as follows:

Return-Path: 0000013e79305031-08aae59a-f7a0-41c9-8bd9-076c46caf100-000000@amazonses.com
Date: Mon, 6 May 2013 09:33:29 +0000
From: Test Account <test@test.com>
To: test@localhost.com
Message-ID: <0000013e79305031-46caf100-000000@email.amazonses.com>
Subject: TEST
Mime-Version: 1.0
Content-Type: multipart/alternative;
  boundary="--==_mimepart_518778e85f16a_56844ceff0898ed";
  charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SES-Outgoing: 129.255.144.108

If the body is shown, the attachment can be found at the end of the source though:

----==_mimepart_518778e85f16a_56844ceff0898ed
Date: Mon, 06 May 2013 09:33:28 +0000
Mime-Version: 1.0
Content-Type: application/pdf;
 charset=UTF-8;
 filename="Test.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
 filename="Test.pdf"
Content-ID: <518778e829b75_56844ceff089553@ip-10-36-149-153.mail>
...

I have found similar errors on Stack Overflow (Problem sending multipart mail using ActionMailer) but the suggested solutions did not work - especially the solution at the bottom is very interesting, as it focuses on a solution without inline attachments (https://stackoverflow.com/a/16334096/1016269). I get an error from AWS though saying that the start boundary is not set - I tried to explicitly set it, but no luck so far.

This is the original code I use for sending the email:

def test_email
    attachments["Test.pdf"] = File.read(Rails.root.join("data", "test.pdf"))
    mail(to: recipient, subject: "Test Email")
end

This is the code based on the solutions suggested in the link I posted:

def test_email
    mixed = mail(to: recipient, subject: "Test Email")

    mixed.add_part(
        Mail::Part.new do
            content_type 'multipart/alternative'
            # THE ODD BIT vv
            mixed.parts.reverse!.delete_if {|p| add_part p }
        end
    )

    mixed.content_type 'multipart/mixed'
    mixed.header['content-type'].parameters[:boundary] = mixed.body.boundary

    attachments["Test.pdf"] = File.read(Rails.root.join("data", "test.pdf"))
 end

The response is:

AWS::SES::ResponseError: InvalidParameterValue - Missing start boundary

Any ideas what could cause this issue?

Thanks a lot

Community
  • 1
  • 1
RaceCondition
  • 307
  • 2
  • 12
  • This could help http://stackoverflow.com/questions/1118592/problem-sending-multipart-mail-using-actionmailer – sites May 06 '13 at 12:47
  • Do you have line error is spawning? – sites May 06 '13 at 12:56
  • I have already looked at the StackOverflow link you attached (I mentioned it above). It only helped to some extent. The error line is: **from /opt/project/shared/bundle/ruby/1.9.1/gems/aws-ses-0.4.4/lib/aws/ses/base.rb:163:in `request'**. As soon as I change the content type to "text/html" for example, it sends out the mail at least. Otherwise it complains about the missing start boundary. – RaceCondition May 07 '13 at 08:29

0 Answers0