Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 3, ActionMailer with AWS SES and attachments in Sparrow and Apple Mail #10520

Closed
dschneider opened this issue May 8, 2013 · 2 comments
Closed

Comments

@dschneider
Copy link

I just copied the text from my Stackoverflow question, as I have already explained the problem there:

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 (http://stackoverflow.com/questions/1118592/problem-sending-multipart-mail-using-actionmailer/7177061#7177061) 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 (http://stackoverflow.com/a/16334096/1016269).

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

I hope that helps to narrow down the problem a little.

Associated question on StackOverflow:

http://stackoverflow.com/questions/16398966/rails-3-actionmailer-with-aws-ses-and-attachments-in-sparrow-and-apple-mail

@laurocaetano
Copy link
Contributor

Hi @dschneider! Have you tested this in Rails 4.0.2?
Rails 3 is not supported anymore.
Also I'm not sure if it's an issue.

Thanks.

@dschneider
Copy link
Author

@laurocaetano We haven't tried upgrading yet, it's a rather big project. I assume it would need some adjustment / testing for the upgrade. I will close. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants