einar k.
2013-Apr-24 21:27 UTC
sending Mail in loop w attachmt -> only 1.mail has the attachment
Hello, i have a Loop where an email is sent to several adresses one by one. works fine, but if i attach a file it works only for the first adress correctly. THe other get the mailtext, but no attachment (coorct name, but 0 Bytes) Any Idea why? TIA Code of the controller: def gruppenmail_schreiben puts "------------------" attach = params[:attachment] params[:auftragnr].each do |t| if t != ''0'' neuemail = Writtenmail.new neuemail.attachment = attach neuemail.betreff = params[:betreff] neuemail.body = params[:body] neuemail.candidate_id = t neuemail.absender = current_fakusers.email neuemail.email = mailsuchen(t) neuemail.save mailsenden(neuemail) end end redirect_to :controller => ''anzeige'', :action => ''suchmaske'' end #Ende gruppenmail_schreiben def mailsenden(mail) Notifier.deliver_multipart_alternative_rich( #t,# mail.email, mail.betreff, mail.body, mail.candidate_id, mail.attachment, mail.absender ) #end end #Ende mailsenden models/notifier Code: def multipart_alternative_rich(email, betreff, inhalt, nr, anhang, absender, sent_at = Time.now) require ''mime/types'' @subject = betreff @recipients = email @from = absender @sent_on = sent_at @body = {:inhalt => inhalt} @content_type = ''text/html'' unless anhang.blank? datentyp = typerkennung(anhang.original_filename) puts datentyp attachment :content_type => "''" + datentyp + "''", :body => anhang.read, :filename => anhang.original_filename end end def typerkennung(dateiname) dateityp = MIME::Types.type_for(dateiname) return dateityp[0] end The Log-Part: Processing AnzeigeController#gruppenmail_schreiben (for 193.25.32.138 at 2013-04-24 14:44:48) [POST] Parameters: {"commit"=>"los", "body"=>"<p>fgdsg</p>", "attachment"=>#<File:/tmp/RackMultipart.24841.0>, "authenticity_token"=>"YGNJMTo4CBlONuQX+GlhfxBkIzCl5xz6u70zWY1fr/g=", "betreff"=>"test", "auftragnr"=>["0", "0", "0", "0", "0", "0", "124", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "16", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"]} Sent mail to e.eckh-ywXsrRw3A2yELgA04lAiVw@public.gmane.org Sent mail to ekre@b.de Redirected to http://mlahsa.de/anzeige/suchmaske Completed in 1764ms (DB: 1) | 302 Found [http://mlahsa.einar-kretzler.de/anzeige/gruppenmail_schreiben] -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2013-Apr-25 08:36 UTC
Re: sending Mail in loop w attachmt -> only 1.mail has the attachment
On Wednesday, April 24, 2013 10:27:50 PM UTC+1, Ruby-Forum.com User wrote:> > Hello, > i have a Loop where an email is sent to several adresses one by one. > works fine, but if i attach a file it works only for the first adress > correctly. THe other get the mailtext, but no attachment (coorct name, > but 0 Bytes) > Any Idea why? > TIA >If the attachment is an IO like object (which seems like it is, from the log), then you''ll probably need to rewind it after it has been read. Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/9s-7Cbi_JIwJ. For more options, visit https://groups.google.com/groups/opt_out.