Hi guys: I wanna send a html format email with a attachment. What I do is like: model: def weekly_report address = WeeklyReportEmail.find_all_by_validate(true).collect(&:address).to_sentence(:last_word_connector => '','', :two_words_connector => '','') @recipients = address @from = "Chronos weekly report <chronos-4ZJPdxLVsvDgESyFIoI21jfzStP7pjZN0E9HWUfgJXw@public.gmane.org>" @subject = "[Chronos] Weekly report" @sent_on = Time.zone.now @body[:projects] = Project.all attachment :content_type => "image/png", :body => File.read(RAILS_ROOT + "/public/images/cancel.png") end views: just a erb file. and the way I sent the mail is like below: mail = MailReport.create_weekly_report mail.set_content_type("text/html") MailReport.deliver(mail) If I sent it like that, I can not get the attachment insted of getting some messy code. I tried sent it like MailReport.deliver_weekly_report. If so, the email will not be a html format email. So what should I do, if I wanna send a html email with attachment.
something like: This is example procedure - assuming that i want to send few pdfs attached with a html email - this is ordinary mailer method class ExampleNotify < ActionMailer::Base def example(_user, _attachments) recipients _user.email from FROM subject ''example'' content_type "text/html; charset=utf-8" body render_message(''example'') for a in _attachments attachment :content_type => "application/pdf", :body => File.read(File.join(RAILS_ROOT,DOCUMENT_DIR,a)), :filename=>a end end end -- Posted via http://www.ruby-forum.com/.
Hi U can try this. User_notifier: def method_name(email) @recipients = email @content_type = "text/html" attachment :content_type => "application/octet-stream", :filename => "User Manual.pdf", :body => File.read("public/User Manual.pdf") end Thanks Seenu On Wed, Oct 28, 2009 at 6:50 PM, Frantisek Psotka < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > something like: > > This is example procedure - assuming that i want to send few pdfs > attached with a html email - this is ordinary mailer method > > > class ExampleNotify < ActionMailer::Base > > def example(_user, _attachments) > recipients _user.email > from FROM > subject ''example'' > content_type "text/html; charset=utf-8" > > body render_message(''example'') > > for a in _attachments > attachment :content_type => "application/pdf", :body => > File.read(File.join(RAILS_ROOT,DOCUMENT_DIR,a)), :filename=>a > end > end > > end > > -- > 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---