Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3: Sending Mail with Attachment - corrupted file after first send
    primarykey
    data
    text
    <p>I want to implement a real simpel newsletter. Therefor I can select as much recipients I want.</p> <p>To that newsletter I can attach a file. This works great for the first mail. All next mails have corrupted attachments (1 byte size).</p> <p>actionmailer:</p> <pre><code>def send_newsletter(recipient,subject,content,file) @content = content if file attachments[file.original_filename] = { :content=&gt; file.read, :mime_type=&gt; file.content_type } end mail(:to =&gt; recipient, :template_name =&gt; "deliver_newsletter", :subject =&gt; subject).deliver! end </code></pre> <p>applicationcontroller:</p> <pre><code> def create @customers = Customer.where("CHAR_LENGTH(email) &gt; 0") @recipients = params[:sent_to] @subject = params[:subject] @content = params[:content].html_safe @file = params[:file] if @recipients @recipients.each do |mail_recipient| Newsletter.send_newsletter(mail_recipient,@subject,@content,@file) end end respond_to do |format| format.html { redirect_to bills_path, notice: "everything works fine" } end end </code></pre> <p>and finally the form for sending newsletters:</p> <pre><code> &lt;%= form_tag ('/newsletters'), :multipart =&gt; true do %&gt; &lt;%= t 'views.newsletter.to_recipient' %&gt;:&lt;br&gt; &lt;%= select_tag 'sent_to', options_from_collection_for_select(@customers, 'email', 'name'), :multiple =&gt; true, :class =&gt; 'sent_to' %&gt;&lt;br&gt;&lt;br&gt; &lt;%= t 'views.newsletter.subject' %&gt;:&lt;br&gt; &lt;%= text_field_tag 'subject' %&gt;&lt;br&gt;&lt;br&gt; &lt;%= t 'views.newsletter.content' %&gt;:&lt;br&gt; &lt;%= text_area_tag 'content', "".html_safe, :size=&gt;"20x8" %&gt;&lt;br&gt;&lt;br&gt; &lt;%= t 'views.newsletter.attachment' %&gt;:&lt;br&gt; &lt;%= file_field_tag 'file' %&gt;&lt;br&gt;&lt;br&gt; &lt;%= submit_tag t('views.buttons.newsletter_send_now'), :class =&gt; "btn btn-primary", :disable_with =&gt; t('views.buttons.newsletter_sending') %&gt; &lt;% end %&gt; </code></pre> <p>another small question: why is "delay" from the "delay_jobs" gem not working here? All other mails can be sent by typing "Newsletter.delay.send_newsletter(...)"</p>
    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.
    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