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

Preview for mail with attachments #135

Closed
jmarceli opened this issue Apr 9, 2015 · 4 comments
Closed

Preview for mail with attachments #135

jmarceli opened this issue Apr 9, 2015 · 4 comments

Comments

@jmarceli
Copy link

jmarceli commented Apr 9, 2015

I'm not sure how it's related to this gem, but when I use skip_premailer: true everything works fine.

Mailer function:

  def confirmation(order, order_file)
    emails = ['someone@dot.com', 'other@mail.com']
    attachments['file.csv'] = File.read(order_file)
    mail(to: emails, subject: 'Order confirmation')
  end

When I send a real email it is OK but doesn't work on email preview page. I get following error:

NoMethodError at /rails/mailers/main_mailer/confirmation
undefined method `mime_type' for #<Array:0x00000009b58318>

Lines pointed in error report:
lib/rails/templates/rails/mailers/email.html.erb

</header>
<iframe seamless name="messageBody" src="?part=<%= Rack::Utils.escape(@part.mime_type) %>"></iframe>
</body>
</html>

I have absolutely no idea how to track down and fix this problem.

@jezstephens
Copy link
Contributor

I've started having this problem after upgrading from premailer-rails 1.4.0 / premailer 1.7.3 to premailer-rails 1.8.0 / premailer 1.8.4 with rails 4.2.1.

Possibly related to rails/rails#14435.

@jezstephens
Copy link
Contributor

Looks like no preview hook was registered until 1.7.0 so Premailer wasn't being used for previews. That explains why I didn't have this problem before.

@jezstephens
Copy link
Contributor

Fairly sure this is a Rails bug. The problem is triggered when Premailer generates a text part, substituting the text/html part with a multipart/alternative part containing the HTML and text parts. This works OK when the original message is HTML only and the resulting multipart message is only one level deep. However, if there is further nesting due to attachments Rails does not search for the HTML part recursively as it should.

There are a couple of open PRs which aim to fix this: rails/rails#14519, rails/rails#15569.

@fphilipe
Copy link
Owner

Closing as this seems to be a rails issue.

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

No branches or pull requests

3 participants