Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3 ActionMailer corrupts attachments
    primarykey
    data
    text
    <p>I'm using Rails 3.2.13 and have been following along with the ActionMailer guide (<a href="http://guides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments" rel="nofollow noreferrer">http://guides.rubyonrails.org/action_mailer_basics.html#sending-emails-with-attachments</a>), but I'm having difficulty with sending email attachments.</p> <p>After execution the email sends properly but the attachment is always corrupted. In particular, I see the rendered email and the correct filename for the attachment but as a 1KB file that can't be opened. I've seen similar issues around stack overflow and elsewhere (e.g. <a href="https://stackoverflow.com/questions/15667565/rails-3-sending-mail-with-attachment-corrupted-file-after-first-send">Rails 3: Sending Mail with Attachment - corrupted file after first send</a> and <a href="https://stackoverflow.com/questions/6105561/rails-3-0-7-actionmailer-attachment-issue">Rails 3.0.7 ActionMailer attachment issue</a>), but none of the solutions offered have been able to help. I've tried two different transports (Gmail SMTP and Sendgrid), several file types (png, pdf, etc.), and both inline and normal attachments, but always with the same effect.</p> <p>Here's the code for the mailer:</p> <pre><code>class UserMailer &lt; ActionMailer::Base # A hash of default values for email messages default from: "me@mysite.com" def welcome_email(user) @user = user @url = "http://localhost:3000" attachments['logo_email.png'] = File.read("public/img/logo_email.png") mail(:to =&gt; user.email, :subject =&gt; "Welcome") end end </code></pre> <p>Where I'm calling it in my controller it looks like this (I'm using delayed_job here, but the attachment is corrupted even without it):</p> <pre><code>UserMailer.delay.welcome_email(@user) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload